收藏
回答

cloud.uploadFile ArrayBuffer 报错

框架类型 问题类型 终端类型 AppID 基础库版本
小程序 Bug 工具 wxf621ea0f45cd64d3 2.7.5

- 当前 Bug 的表现(可附上截图)


- 预期表现


- 复现路径


- 提供一个最简复现 Demo

//小程序

async submitImages() {
 
    let pageData = this.data;
 
    let fm = wx.getFileSystemManager();
 
    await this.data.cover_url_list.forEach(item => {
 
        fm.readFile({

            filePath: item,

           //返回 ArrayBuffer

            // encoding: "base64",
            success: res => {
                // console.log("imgbase64:"+res.data)
                    wx.cloud.callFunction({
                        // 云函数名称
                        name: 'upload_album',
                        // 传给云函数的参数
                        data: {
                            imageArrayBuffer: res.data
                        },
                        success: res => {
                            console.log(res);
                        },
                        fail: res => {
                            console.log(res);
                        },
                        complete: res => {
                            // console.log('callFunction test result: ', res)
                        },
                    })
                
            }
        })
    })
},




//云函数

// 云函数入口函数
exports.main = async(event, context) => {
 
    return await cloud.uploadFile({
        cloudPath: 'demo.jpg',
        fileContent: event.imageArrayBuffer.data,
    })
}


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

1 个回答

  • 邓坤力
    邓坤力
    2019-07-21

    在云函数中需先转换回 buffer

    2019-07-21
    有用
    回复 1
    • 王政娇
      王政娇
      2020-07-28
      const fileContent = Buffer.from(event.imageArrayBuffer.data)
      这样转不行呢
      2020-07-28
      回复
登录 后发表内容