作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
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);
});
}
req.files.pin_img
不正确。我哪里错了吗??
最佳答案
下面对我有用。确保你有正确的配置。桶。您会使用 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)
});
关于node.js - 如何将图像上传到 AWS S3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47535820/
我是一名优秀的程序员,十分优秀!