簡體   English   中英

通過使用 Express-fileupload 庫,將圖像上傳到 AWS S3 存儲桶

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

任何人請幫助我,通過使用 express-fileupload 庫,我想使用 restful API 將我的文件和圖像上傳到 AWS S3 存儲桶。

希望你找到了答案。 如果你還沒有找到答案,這是我剛剛發現的

 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()

將返回一個對象,其中包含您上傳的文件的位置,實際上您可以自己生成它,但如果發生任何錯誤,這將不包括在內,所以我認為我在這里發布的內容是一個更好的解決方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM