【发布时间】:2021-05-14 04:29:51
【问题描述】:
假设从客户端input 获取file 在下面的服务器函数中。
console.log(file) 是
{
filename: '20200608_110520.jpg',
mimetype: 'image/jpeg',
encoding: '7bit',
createReadStream: [Function: createReadStream]
}
现在我想将此文件上传到 aws s3。我混淆了上面的文件是什么。错误消息file 应该是type string、an instsance of Buffer、ArrayBuffer 之一。但上面只是一个对象。正确的?那是什么?是Blob 吗?或File ?还是只是一个Object?如何将其转换为正确的?
const imageUpload = async (file) => {
...
const s3 = new AWS.S3()
const params = {
Bucket: S3_BUCKET,
Key: 'CoolFileName',
Body: file,
}
const { Location, Key } = await s3.upload(params).promise()
// TypeError [ERR_INVALID_ARG_TYPE]:
// The first argument must be of type string or
// an instance of Buffer, ArrayBuffer, or Array
// or an Array-like Object. Received an instance of Object**
}
我正在使用 GraphQL...我认为它使这变得复杂...
【问题讨论】:
标签: node.js file amazon-s3 buffer