云函数本地调试上传文件uploadFile函数一直报元数据获取失败?
发布于 6 年前 作者 tkong 4884 次浏览 来自 官方Issues

大致源码如下, 路径没有问题:

const cloud = require('wx-server-sdk')
const fs = require('fs')
const path = require('path')
cloud.init({env: 'develop'})
 
 
exports.main = async (event, context) => {
 
var readerStream = fs.createReadStream('demo.txt');
var data = '';

 
// 处理流事件 --> data, end, and error
readerStream.on('data', function(chunk) {
   data += chunk;
});
 
readerStream.on('end',function(){
     console.log('demo.jpg!!!!')
     cloud.uploadFile({
       cloudPath: 'demo.txt',
       fileContent: readerStream,
     })

});


//more...

}


报错截图:

1 回复

var buffer = fs.readFileSync(__dirname+’/demo.txt’)

cloud.uploadFile({

cloudPath:‘demo.txt’,

fileContent: buffer

})

回到顶部