收藏
回答

云函数上传文件报错@cloudbase/node-sdk文件中的url未定义?

云函数API:cloud.uploadFile()

在执行云函数时,报错信息如下:

读取失败 Error: cloud.callFunction:fail Error: errCode: -504002 functions execute fail | errMsg: TypeErruploadFile:fail or: uploadFile:fail Cannot read property 'token' of undefined

    at Object.uploadFile (/var/user/node_modules/@cloudbase/node-sdk/lib/storage/index.js:32:21)

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

    at async Object.uploadFile (/var/user/node_modules/wx-server-sdk/index.js:703:17)

    at async /var/user/node_modules/wx-server-sdk/index.js:2784:32 (callId: 1636300153341-0.19951325707361667)


已经尝试

npm i @cloudbase/cli@latest -g --registy https://registry.npm.taobao.org/

也尝试过重新安装依赖,没有效果

源文件如下:

  //4,把excel文件保存到云存储里
    let res = await cloud.uploadFile({
      cloudPath'test.xlsx',
      // cloudPath: dataCVS,
      fileContent: buffer, //excel二进制文件
    })
    return res


也扒过 @cloudbase/node-sdk/lib/storage/index.js 文件,源代码如下:

async function uploadFile(cloudbase, { cloudPath, fileContent }, opts{
    const { data: { url, token, authorization, fileId, cosFileId } } = await getUploadMetadata(cloudbase, { cloudPath }, opts);
    //*****就在这里的url报错,显示未定义*****
        const formData = {
        Signature: authorization,
        'x-cos-security-token': token,
        'x-cos-meta-fileid': cosFileId,
        key: cloudPath,
        file: fileContent
    };
    let body = await new Promise((resolve, reject) => {
        request_1.default({ url, formData: formData, method'post' }, function (err, res, body{
            if (err) {
                reject(err);
            }
            else {
                resolve(body);
            }
        });
    });
}),
回答关注问题邀请回答
收藏
登录 后发表内容