如何将图像上传到AWS S3

M g*_*wda 3 node.js postman

如何在我的post API中访问该键名<code>req.files.pin_img</code>我传递的表单数据不正确.我错了吗?<p></p></p>
    </div>
  </div>

<div class=

shi*_*kar 6

下面适合我.确保你有正确的配置.桶.你会发现使用https://appname.s3-accelerate.amazonaws.com/aws_test.jpg找到上传的图像

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)
});
Run Code Online (Sandbox Code Playgroud)