相关疑难解决方法(0)

从url下载文件并将其上传到AWS S3而不保存 - node.js

我正在编写一个从URL下载图像的应用程序,然后使用aws-sdk将其上传到S3存储桶.

我以前只是下载图像并将它们保存到磁盘上.

request.head(url, function(err, res, body){

    request(url).pipe(fs.createWriteStream(image_path));

});
Run Code Online (Sandbox Code Playgroud)

然后像这样将图像上传到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");
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

但我想跳过将图像保存到磁盘的部分.有什么方法可以pipe将响应request(url)转换为变量然后上传吗?

javascript amazon-s3 fs amazon-web-services node.js

25
推荐指数
3
解决办法
2万
查看次数

标签 统计

amazon-s3 ×1

amazon-web-services ×1

fs ×1

javascript ×1

node.js ×1