- 当前 Bug 的表现(可附上截图)
返回结果:
{"errorCode":1,"errorMessage":"user code exception caught","stackTrace":"Error: errCode: -501001 resource system error | errMsg: uploadFile:fail MultipartParser.end(): stream ended unexpectedly: state = PART_DATA; at uploadFile api; \n at new CloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:2679:28)\n at returnAsCloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:2731:16)\n at Object.returnAsFinalCloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:2745:13)\n at Object.\u003canonymous\u003e (/var/user/node_modules/wx-server-sdk/index.js:2213:58)\n at step (/var/user/node_modules/tslib/tslib.js:133:27)\n at Object.throw (/var/user/node_modules/tslib/tslib.js:114:57)\n at rejected (/var/user/node_modules/tslib/tslib.js:105:69)\n at \u003canonymous\u003e\n at process._tickCallback (internal/process/next_tick.js:188:7)"}
- 预期表现
传入了要求的参数【可读流】,调用应该成功
- 复现路径
- 提供一个最简复现 Demo
提供三种云函数调用case,均无法实现写数据到存储,本地测试创建的可读流没有问题
const cloud = require('wx-server-sdk')
const fs = require('fs')
const streamifier = require('streamifier')
var streamBuffers = require('stream-buffers');
cloud.init()
exports.main = async (event, context) => {
/* --------------------------case0---------------------------------
var readerStream = new stream.PassThrough();
readerStream.end(new Buffer('Test data.'));
----------------------------------------------------------------------*/
/* --------------------------case1---------------------------------
let readerStream = streamifier.createReadStream(new Buffer('Test data.'))
----------------------------------------------------------------------*/
/* --------------------------case2---------------------------------
var readerStream = new streamBuffers.ReadableStreamBuffer({
frequency: 10, // in milliseconds.
chunkSize: 2048 // in bytes.
});
readerStream.put('Test data.');
readerStream.stop();
----------------------------------------------------------------------*/
return await cloud.uploadFile({
cloudPath: 'demo.txt',
fileContent: readerStream
})
}
微信小程序开发问题解答
微信小程序开发者回答:
云函数的 空间只能读不能写 。就算能写也没意义,因为运行完就销毁。文件读写请用云存储
微信小程序开发者回答:
或者说【微信小程序云开发】只能做文件的【搬运工】,不能做文件的生【产者吗】?
微信小程序开发者回答:
官方说的数据类型是fs.ReadStream
用fs.createReadStream来获取流数据
let readStream = fs.createReadStream('你的文件路径');
本文网址:http://www.91bianli.com/weixinxiaochengxu/41525.html