1
我希望能夠將圖像從URL保存到S3。我已經能夠做到通過允許用戶通過使用此代碼(docs here)上傳個人資料圖片類似的東西:在node.js中將URL從URL保存到S3
uploadUserImage: function(req, res) {
var userName = req.params.username;
var fname = userName + ".jpg";
var userAvatar = "https://.......;
req.file('image').upload({
adapter: require('skipper-s3'),
key:'xxxxxxxxxxxx',
secret:'xxxxxxxxxx',
region: "xxxxxx",
bucket: 'xxxxxxx',
headers: {
ACL: 'public-read'
},
saveAs: "user-images/"+fname
}, function whenDone(err, uploadedFiles) {
反正是有,我可以修改這個代碼,所以我可以從一個URL /鏈接保存圖像?
我一直在嘗試做這樣的事情,但我無法弄清楚它是如何工作的。
var request = require('request');
function(person, next) {
request({
url:person.image,
encoding:null
}, function(err, res, reqBody) {
if (err) {
console.log(err);
} else {
console.log(reqBody);
console.log(res);
}
reqBody.upload({
adapter: require('skipper-s3'),
key:'xxxxxxxxxxxx',
secret:'xxxxxxxxxx',
region: "xxxxxx",
bucket: 'xxxxxxx',
headers: {
ACL: 'public-read'
},
saveAs: "user-images/"+person.id+".jpeg"
}, function whenDone(err, uploadedFiles) {
if(err) {
return next(err);
} else {
person.image = "https:........";
return next(null, person);
}
});
});
},