将缓冲区传递到 fs.createReadStream() 不起作用
所以我有一个像这样的 JSON 对象一样的 Alamofire 请求:
{
fieldname: 'photo',
originalname: 'pic',
encoding: '7bit',
mimetype: 'image/jpg',
buffer: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 02 01 00 48 00 48 00 00 ff e1 3e cc 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 06 01 12 00 03 00 00 00 01 00 03 ... 5093173 more bytes>,
size: 5093223
}
我有一个函数“uploadFile”,如下所示:
function uploadFile(file) {
const fileStream = fs.createReadStream(file.path);
const uploadParams = {
Bucket: bucketName,
Body: fileStream,
Key: file.filename,
};
return s3.upload(uploadParams).promise();
}
我需要将缓冲区传递到 uploadFile 函数中,但由于某种原因,我不断收到错误消息“TypeError [ERR_INVALID_ARG_TYPE]” :“path”参数必须是字符串类型或者 Buffer 或 URL 的实例。收到未定义。
我尝试传入 request.buffer 和 Buffer.from(request.buffer)。不知道还能尝试什么,但 Buffer.isBuffer(request.buffer) 返回 true,所以我不知道在这里要做什么。
So I have an Alamofire request coming in like this JSON object:
{
fieldname: 'photo',
originalname: 'pic',
encoding: '7bit',
mimetype: 'image/jpg',
buffer: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 02 01 00 48 00 48 00 00 ff e1 3e cc 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 06 01 12 00 03 00 00 00 01 00 03 ... 5093173 more bytes>,
size: 5093223
}
I have a function 'uploadFile' seen below:
function uploadFile(file) {
const fileStream = fs.createReadStream(file.path);
const uploadParams = {
Bucket: bucketName,
Body: fileStream,
Key: file.filename,
};
return s3.upload(uploadParams).promise();
}
I need to pass the Buffer into the uploadFile function, but for some reason I keep getting an error that says 'TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined.'
I've tried passing in request.buffer, and Buffer.from(request.buffer). Not sure what else to try, but Buffer.isBuffer(request.buffer) returns true so I'm not sure what to do here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论