php convert images and upload to amazon s3
I am looking for a best practice while uploading images to amazon s3 server and serving from there.
We need four different sizes of an image. So just after image upload we convert the image and scale in 4 different widths a开发者_运维知识库nd heights. And then we send them to the amazon s3 using official php api.
// ...
// image conversions, bucket setting, s3 initialization etc.
$sizes= array("", "48", "64", "128");
foreach($sizes as $size) {
$filename = $upload_path.$dest_file.$size.$ext;
$s3->batch()->create_object($bucket, , array(
'fileUpload' => $filename,
'acl' => AmazonS3::ACL_PUBLIC,
));
}
But for a 1M image the client sometimes wait up to 30 seconds which is a very long time.
Instead of sending images immediately to S3, it may be better to add them to a job queue. But the user should see the uploaded image immediately.
You could simply achieve that by queuing the files, in for example: a database, and then running a cron job, or having a constantly running php script. If you say you want the users to see the images instantly, should they see them instantly on S3?
精彩评论