我的做是
client base64化数据
server Buffer.from 转换成 Buffer 对象上传
'use strict';
/**
* add
*/
const tools = require('tools');
module.exports = async function(event) {
uniCloud.logger.log('======add========')
let result;
delete event.action;
result = Buffer.from(event.file, 'base64').toJSON();
uniCloud.uploadFile({
cloudPath: event.name,
filePath: result,
success(e) {
console.log(e);
},
fail(e) {
console.log(e);
}
})
result = await uniCloud.uploadFile({
filePath: result,
cloudPath: event.name,
fileType: 'image'
});
uniCloud.logger.log('======add end====')
return result;
}
TypeError: e.$scope.file.uploadFile is not a function
at st.uploadFile (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/unicloud/aliyun/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:1483)
at module.exports (/Users/zh/Documents/workspace/zorg/z-coupon-org/cloudfunctions-aliyun/upload/add.js:22:26)
at Object.exports.main (/Users/zh/Documents/workspace/zorg/z-coupon-org/cloudfunctions-aliyun/upload/index.js:23:19)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
at Function.Module.runMain (module.js:695:11)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
[z-coupon-org] 18:34:56.458 [本地运行:阿里云:z-coupon-org]运行状态:失败
H***@qq.com (作者)
这个插件我看过,我的客户端是后台,
1、后台上传文件并不能用uni.uploadfile,只能用restapi
2、代码错误是云函数代码中uniCloud.uploadFile 报错 e.$scope.file.uploadFile is not a function
2020-12-09 11:20
DCloud_uniCloud_JSON
回复 H***@qq.com: 你用的阿里云版还是腾讯云版unicloud
2020-12-09 11:51
H***@qq.com (作者)
回复 DCloud_uniCloud_JSON: 阿里云
2020-12-09 11:55
DCloud_uniCloud_JSON
回复 H***@qq.com: 文档已经说明了阿里云不支持哦。 https://uniapp.dcloud.io/uniCloud/storage?id=clouduploadfile
2020-12-09 11:56
H***@qq.com (作者)
回复 DCloud_uniCloud_JSON: 好的吧 太难了
2020-12-09 12:05
H***@qq.com (作者)
回复 DCloud_uniCloud_JSON: 最后我使用阿里云调用腾讯云搞定了 能用钱搞定的事早说呀
2020-12-09 16:09
DCloud_uniCloud_JSON
回复 H***@qq.com: 哈哈,文档不是写了么。
2020-12-09 20:52
l***@163.com
回复 DCloud_uniCloud_JSON: HBuilder X3.1.0+不是支持阿里云了吗? 我这怎么还不能上传,一直提示Invalid options.filePath
2021-02-06 09:44