【发布时间】:2014-04-06 21:00:01
【问题描述】:
我正在编写一个应用程序,它从 url 下载图像,然后使用 aws-sdk 将其上传到 S3 存储桶。
以前我只是像这样下载图像并将它们保存到磁盘。
request.head(url, function(err, res, body){
request(url).pipe(fs.createWriteStream(image_path));
});
然后像这样将图像上传到 AWS S3
fs.readFile(image_path, function(err, data){
s3.client.putObject({
Bucket: 'myBucket',
Key: image_path,
Body: data
ACL:'public-read'
}, function(err, resp) {
if(err){
console.log("error in s3 put object cb");
} else {
console.log(resp);
console.log("successfully added image to s3");
}
});
});
但我想跳过将图像保存到磁盘的部分。有什么方法可以pipe 将来自request(url) 的响应发送到变量然后上传?
【问题讨论】:
-
这可以在 iOS 中做同样的事情吗?
标签: javascript node.js amazon-web-services amazon-s3 fs