如何将图像上传到AWS S3

如何在我的post API中访问这个键名<code> pin_img </ code>

pin.js

function uploadPinMedia(req, res, next) { var s3 = new AWS.S3({ accessKeyId: 'AKIAIUCBE3TQGL6ATPBA', secretAccessKey: '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', Bucket: 'mapery-v2' }); var data = { Bucket: 'mapery-v2', Key: 'upload-v2', Body: req.files.pin_img }; s3.putObject(data, function(err, media_res) { if(err) console.log('error uploading data', media_res); console.log(media_res); }); } 

我试图从邮差上传一个图像到s3桶,但它似乎是我传递的forms数据req.files.pin_img是不正确的。 我错了吗?

下面为我​​工作。 确保你有正确的configuration。 桶。 您将使用https://appname.s3-accelerate.amazonaws.com/aws_test.jpgfind上传的图&#x7247;

 const AWS = require('aws-sdk'); AWS.config.update({ accessKeyId: process.env.AWS_KeyId, secretAccessKey: process.env.AWS_secret, // region:process.env.AWS_region }); const s3 = new AWS.S3({ signatureVersion: 'v4', }) var photoBucket = new AWS.S3({ params: { Bucket: 'bucket' } }) photoBucket.upload({ ACL: 'public-read', Body: fs.createReadStream('./test.jpg'), // file upload by below name Key: 'aws_test.jpg', ContentType: 'application/octet-stream' // force download if it's accessed as a top location },(err, response)=>{ console.log(err, response) });