收藏
回答

wx.cloud.cdn上传返回url,云函数里怎么用这个url下载已上传的数据内容?

为了减少数据库读写次数,

项目需要一次add几十条大记录到云开发的数据库集合中,

方法是中间建一个云函数接受小程序端的record数组,

然后remove掉之前的数据再一次add进去。

但是记录超过80kb,

云函数就会报超时的错误。

后来查得用wx.cloud.cdn标记上传可以解决问题,

然而在云函数中,用获得的wx.cloud.cdn返回url获取上传数据却遇到问题。

首先使用cloud.downloadfile下载(rs.ss=await cloud.downloadfile({fileId:‘http://vweixinf.tc.qq.com/301/20303/stodownload?m=0b867e53c1d233ce9fe49d54549a2323&filekey=3033020101041f301d0202012d0402535a04100b867e53c1d233ce9fe49d54549a232302010d040d00000004627466730000000131&hy=SZ&storeid=323032323036323631333438323130303065646132666439633733343832386536313838303930303030303132643030303034663466&bizid=1023’})),

报错:SaveHouse->wx.cf->house.update.all Error: cloud.callFunction:fail Error: errCode: -504002 functions execute fail | errMsg: Error: downloadFile:fail -501007 invalid parameters. 

    at toSDKError (:59277/var/user/node_modules/wx-server-sdk/index.js:8089)

    at Object.returnAsFinalCloudSDKError (:59277/var/user/node_modules/wx-server-sdk/index.js:8060)

    at :59277/var/user/node_modules/wx-server-sdk/index.js:2685

    at processTicksAndRejections (:59277/appservice/internal/process/task_queues.js:97) (callId: 1656225486984-0.2214185235687418) (trace: 14:38:6 start->14:38:8 system error (Error: errCode: -504002 functions execute fail | errMsg: Error: downloadFile:fail -501007 invalid parameters. 

    at toSDKError (:59277/var/user/node_modules/wx-server-sdk/index.js:8089)

    at Object.returnAsFinalCloudSDKError (:59277/var/user/node_modules/wx-server-sdk/index.js:8060)

    at :59277/var/user/node_modules/wx-server-sdk/index.js:2685

    at processTicksAndRejections (:59277/appservice/internal/process/task_queues.js:97)), abort)

    at S (WASubContext.js?t=wechat&s=1656201220971&v=2.24.6:2)

    at WASubContext.js?t=wechat&s=1656201220971&v=2.24.6:2

    at WASubContext.js?t=wechat&s=1656201220971&v=2.24.6:2

    at n (WASubContext.js?t=wechat&s=1656201220971&v=2.24.6:2)

遇到这个问题,一直没有找到解决方案

回答关注问题邀请回答
收藏

3 个回答

  • 新乾驾校张教练
    新乾驾校张教练
    2022-06-26

    这个方法也试过,

    小程序端

     wx.cloud.callFunction({

            name:'house',

            data:{

              type:'house.update.all',

              opId:that.GetOpid(that),

              rows:wx.cloud.CDN(rows)

            }

    云函数端

    rs.ss=await axios.get(event.rows)

    但我这边返回的错误如下:

    call failed:, Error: cloud.callFunction:fail Error: errCode: -504002 functions execute fail | errMsg: TypeError: Converting circular structure to JSON

        --> starting at object with constructor 'ClientRequest'

        |     property 'socket' -> object with constructor 'Socket'

        --- property '_httpMessage' closes the circle

        at JSON.stringify (<anonymous>)

        at callback (/var/runtime/node12/CallbackContext.js:31:23)

        at /var/runtime/node12/CallbackContext.js:81:16

        at /var/runtime/node12/Runtime.engine.js:237:13

        at processTicksAndRejections (internal/process/task_queues.js:97:5) (callId: 1656226368561-0.25930267181093436) (trace: 14:52:48 start->14:52:49 system error (Error: errCode: -504002 functions execute fail | errMsg: TypeError: Converting circular structure to JSON

        --> starting at object with constructor 'ClientRequest'

        |     property 'socket' -> object with constructor 'Socket'

        --- property '_httpMessage' closes the circle

        at JSON.stringify (<anonymous>)

        at callback (/var/runtime/node12/CallbackContext.js:31:23)

        at /var/runtime/node12/CallbackContext.js:81:16

        at /var/runtime/node12/Runtime.engine.js:237:13

        at processTicksAndRejections (internal/process/task_queues.js:97:5)), abort)

        at S (http://127.0.0.1:59277/appservice/__dev__/WASubContext.js?t=wechat&s=1656201220971&v=2.24.6:2:246848)

        at http://127.0.0.1:59277/appservice/__dev__/WASubContext.js?t=wechat&s=1656201220971&v=2.24.6:2:273369

        at http://127.0.0.1:59277/appservice/__dev__/WASubContext.js?t=wechat&s=1656201220971&v=2.24.6:2:47439

        at n (http://127.0.0.1:59277/appservice/__dev__/WASubContext.js?t=wechat&s=1656201220971&v=2.24.6:2:24316)

    2022-06-26
    有用 1
    回复
  • 龙安清
    龙安清
    2022-08-12

    在云函数端下载可以使用node.js的request-promise(导出数据到excel表格中)

    1、引入request-promise

    const rp = require('request-promise'); 

    2、从临时链拉取数据,我的数据datas是以字符串的形式传递的

    const {datas}=event

          const temp = await rp(datas).then((res) => {

            //res为请求到的数据,为string类型

            console.log('res', res)

            return res

          })

    3、把收到的数据转化为数组,写入excel表格

    JSON.parse(temp)



    2022-08-12
    有用
    回复
  • Mr.Zhao
    Mr.Zhao
    发表于移动端
    2022-06-26
    不用云开发就懵了,下载可以用axios got request等
    2022-06-26
    有用
    回复 7
    • 新乾驾校张教练
      新乾驾校张教练
      2022-06-26
      有没有axios的详细示例,我这边会报错
      2022-06-26
      回复
    • Mr.Zhao
      Mr.Zhao
      2022-06-26回复新乾驾校张教练
      百度axios下载网络图片或者文件   这个跟云开发 小程序一点关系都没有  nodejs基础操作
      2022-06-26
      回复
    • 新乾驾校张教练
      新乾驾校张教练
      2022-06-26
      我的问题是,使用rs.ss=await axios.get(event.rows)出现这个错误不知道怎么解决?谢谢
      2022-06-26
      回复
    • Mr.Zhao
      Mr.Zhao
      2022-06-26回复新乾驾校张教练
      rows是啥?
      2022-06-26
      回复
    • 新乾驾校张教练
      新乾驾校张教练
      2022-06-26
      wx.cloud.cdn返回的url
      2022-06-26
      回复
    查看更多(2)
登录 后发表内容