gpt4 book ai didi

node.js - 如何将图像上传到 AWS S3

转载 作者:搜寻专家 更新时间:2023-10-31 23:34:19 24 4
gpt4 key购买 nike

How to access that key name <code>pin_img</code> in my post API

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);
});

}
我正在尝试从 postman 将图像上传到 s3 存储桶,但它似乎是我传递的表单数据 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com