简体   繁体   中英

By using Express-fileupload library ,Upload image to AWS S3 bucket

任何人请帮助我,通过使用 express-fileupload 库,我想使用 restful API 将我的文件和图像上传到 AWS S3 存储桶。

Hope you found the answer. In case you haven't found the answer, here is what I just found out

 const uploadSingleImage = async (file, s3, fileName) => { const bucketName = process.env.S3_BUCKET_NAME; if (!file.mimetype.startsWith('image')) { return { status: false, message: 'File uploaded is not an image' }; } const params = { Bucket: bucketName, Key: fileName, Body: file.data, ACL: 'public-read', ContentType: file.mimetype, }; return s3.upload(params).promise(); };

s3.upload(params).promise()

will return an object which contains the Location of the file you uploaded, in fact you could generate it yourself but that would not cover in case any error occur so I think what I posted here is a better solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM