简体   繁体   中英

Resize images while uploading to Amazon S3 bucket

I am Developing an API in PHP and I have to upload images with resize. How can I resize images while uploading to an Amazon S3 bucket?

I have to upload the maximum dimensions of 1920*1080 images

The 'AWS way' would be to create an s3 event notification for the bucket you are uploading images to, and then have an Lambda function get called each time a new file is put into the bucket - the lambda function would do the resizing and either save the new image to a different location or a different name.

All your PHP app needs to do is 'put' the object in the bucket, and let lambda do the rest - quite certain there are lots of examples around the internet to do this exact thing.

You have to resize the images locally with PHP first before uploading them to S3. You can use an already available PHP library for resizing, for example php-image-resize .

I would recommend using image optimization services like Cloudinary which can directly connect to AWS bucket. But this is available in Paid plans only as explained in https://support.cloudinary.com/hc/en-us/articles/202520492-Can-images-be-stored-in-my-own-S3-bucket-

Another way can be to host clone of Imgur; another image optimization service on your own S3. Process explained here: https://hackernoon.com/building-a-highly-scalable-imgur-clone-with-lambda-and-s3-aaf9da422c3e

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