我正在尝试传递API中的密钥,但作为回应,我不是该图像的URL。
我正在使用multer S3上传图片。
虽然上传该网址正在生成,但在GET API的共鸣中,它并未到来。
如何获取该网址。 以下是我的代码: -
//node js code
var multer = require('multer')
//var upload = multer({ dest: 'public/uploads/' });
var aws = require('aws-sdk');
var multerS3 = require('multer-s3');
aws.config.loadFromPath('./config.json');
aws.config.update({
signatureVersion: 'v4'
});
var s0 = new aws.S3({})
var upload = multer({
storage:multerS3({
s3:s0,
bucket:'bucketName',
contentType: multerS3.AUTO_CONTENT_TYPE,
acl: 'public-read',
metadata: function (req, file, cb) {
cb(null, {fieldName: file.fieldname});
},
key: function (req, file, cb) {
cb(null, Date.now().toString())
}
})
})
//for posting
router.post('/profile/upload', upload.single('event_logo'), function(req, res, next){
console.log("req.file",req.file);
res.send(req.file);
});
//for retrieving
router.get('/profile/get/:id',function(req,res){
var item = req.params.id;
var params = {Bucket: 'bucketName', Key : req.params.id};
s0.getObject(params, function (err, data) {
if (err) {
return res.send({ "error": err });
}
res.send({ data });
});
});
//This is the response I am getting while hitting get Api
{
"data": {
"AcceptRanges": "bytes",
"LastModified": "2017-07-01T10:54:26.000Z",
"ContentLength": 225100,
"ETag": "\"b10557805b4ffd815f888eb9e60a9266\"",
"VersionId": "null",
"ContentType": "image/png",
"Metadata": {
"fieldname": "event_logo"
},
"Body": {
"type": "Buffer",
"data": [
209,
155,
158,
166,
9,
119,
32,
116,
73,
95,
193,
52,
190,
19,
64,
146,........
]
}
}
}