H***@qq.com
H***@qq.com
  • 发布:2020-12-08 18:49
  • 更新:2020-12-09 11:13
  • 阅读:1066

云函数 URL 上传文件

分类:uniCloud

我的做是
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]运行状态:失败

2020-12-08 18:49 负责人:无 分享
已邀请:
DCloud_uniCloud_JSON

该问题目前已经被锁定, 无法添加新回复