'use strict';
exports.main = async (event, context) => {
//event为客户端上传的参数
console.log('event : ', event)
let body = JSON.parse(event.body);
console.log('body : ', body)
console.log('body.filepath : ', body.filepath)
let result = await uniCloud.uploadFile({
cloudPath: '123.txt',
fileContent: body.buffer,
});
event.fileID=result.fileID
event.requestId=result.requestId
//返回数据给客户端
return event
};
- 发布:2022-06-07 18:17
- 更新:2022-12-16 01:08
- 阅读:1650
产品分类: uniCloud/App
示例代码:
操作步骤:
文件存入云存储
文件存入云存储
预期结果:
完成文件存入云存储
完成文件存入云存储
实际结果:
各种提示和文档不符合
各种提示和文档不符合
bug描述:
uniCloud.uploadFile
提示信息与文档不相干 提示
情况1
[file-opration/ac1402031654596366920155975/77ms/ERROR] 参数校验错误: Invalid options.filePath
Error: 参数校验错误: Invalid options.filePath
at E (/code/index.js:34:17924)
at uploadFile (/code/index.js:227:475630)
at (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:2894)
at exports.main (/tmp/function/__index.js:10:30)
at i (/tmp/function/index.js:1:2982)
at p (/tmp/function/index.js:1:3580)
at runUserFunction (/code/index.js:118:207833)
at (<anonymous>)
at _tickCallback (internal/process/next_tick.js:189:7)
请求响应状态: fail
把cloudPath换成filePath
其他情况 这个只是举例 如果fileContent不传
情况2
[file-opration/ac1425191654596791187149132/74ms/ERROR] 参数校验错误: filePath和fileBuffer不能都为空
Error: 参数校验错误: filePath和fileBuffer不能都为空
at E (/code/index.js:34:17924)
at uploadFile (/code/index.js:227:475835)
at (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:2894)
at exports.main (/tmp/function/__index.js:10:30)
at i (/tmp/function/index.js:1:2982)
at p (/tmp/function/index.js:1:3580)
at runUserFunction (/code/index.js:118:207833)
at (<anonymous>)
at _tickCallback (internal/process/next_tick.js:189:7)
请求响应状态: fail
照着这份文档 完全没办法完成这个功能
2***@qq.com (作者)
你可以看下request的日志 buffer是没问题的
[file-opration/ac1425191654596791187149132/69ms/DEBUG] body : { filepath: '123456.txt',
buffer:
[ 100,
99,
97,
56,
100,
52,
49,
101,
101,
50,
101,
51,
101,
101,
54,
55,
55,
97,
50,
56,
99,
53,
53,
57,
53,
49,
52,
97,
52,
51,
100,
55 ] }
2***@qq.com (作者)
还是说这个buffer指的不是btye数组