简体   繁体   中英

How to Compress and save image in Amazon server in rest API

I am working on saving compressing and saving image on AWS server. Currently using PutObjectRequest of com.amazonaws.services.s3.model to save the image. I checked online and everywhere following code is used to save image on disk.

writer.write(null, new IIOImage(image, null, null), param);

I am confused on how to compress it first and then send the inputstream to save in the server. how do i compress the image in rest API and save it in AWS server?

Instead of a synchronous flow in your code where you do the compression before upload, you can follow the following approach.

  • Upload the uncompressed image to S3.
  • From S3 have a Lambda trigger which will be invoked upon image upload.
  • In the Lambda code, download the image to the /tmp directory do the compression there and upload it back to S3.

This approach is highly scalable and a pattern used for creating thumbnails of the images & etc. (You should be able to find a Lambda template for Thumbnail creation which you can modify for this)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM