在node.js

时间:2017-09-16 05:30:45

标签: node.js image express amazon-s3

我正在创建一个图片上传系统(尺寸通常> 20MB <50MB),我想将这些图像裁剪成各种尺寸(用于查看移动,网络和桌面应用程序),所有图像都存储在AWS s3中。< / p>

以下是裁剪尺寸的快照

[{
 width:200,
 height:200,
 type:"small",
 platform:"web"},
{
 width:300,
 height:400,
 type:"small",
 platform:"mobile-android"
}
....
....
 ]

以下是我计划做的事情

1.首先将图像上传到S3。

2.在异步任务中运行所有裁剪操作

upload:function(req,res){

    //various cropsizes
    var cropSizes = [];
    //upload image to s3
    uploadImageToS3(req.file,function(err,result){
        if(!err){
            //create crop
            cropImage({
                'cropsizes':cropSizes,
                'file':req.file
            },function(err,result){
                console.log('all crop completed',result);
            });

            res.send('run crop in backgroud');
        }
    });

}

但这是正确的方法吗?任何人都可以拥有比这更好的东西???

1 个答案:

答案 0 :(得分:1)

由于您已经在使用s3,我建议您尝试使用aws lambda来调整图像大小并将其添加回具有新大小的s3存储桶。 以下是此链接https://aws.amazon.com/blogs/compute/resize-images-on-the-fly-with-amazon-s3-aws-lambda-and-amazon-api-gateway/

中的详细说明