3

Currently i have two buckets in S3 - let's call them buck and buck_thumb. Right now, when i uploads an image in to the buck bucket, which triggers a lambda function that resizes the image into a thumbnail and uploads the thumbnail into the buck_thumb bucket.

But now i want to make it like - when i send a image url in buck bucket then it download the image and re size it .

Is there a way ? I can do this using only one bucket?

4

2 回答 2

5

我所做的是我将 lambda 函数设置为 SNS 消息事件,所以当我上传到 S3 存储桶时,我从我的服务器发送一条 SNS 消息到配置的 url,并且该消息是 S3 上文件的整个路径,所以 Lambda可以下载它,调整它的大小,然后用 thumb_ 或其他方式上传。

希望能帮助到你!这是 4 个月前,但是...我希望它可以帮助未来的访客 XD

于 2015-08-05T16:07:16.480 回答
1

如果你简单地这样做,那么你上传 -> 调整大小 -> 上传 -> 调整大小.....无限循环。因此,您应该过滤图像的大小。如果图像的尺寸已经合适,请停止该功能。

gm(data.Body)
.size(function (err, size) {
  if(err){
    callback('gm(data.Body) error');
    context.fail(err);
  }
  if (size.width <= resizeWidth && size.height <= resizeHeight) {
    console.log('already resized')
    context.succeed({
    "error":false
     });
   }
 });
于 2019-03-08T07:13:29.527 回答