Is there a way to grab an image using URL and save it directly to Amazon?
Can it be done using PHP?
My other option was to save file locally and send it using the S3 PHP class.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you “grab the image”, you are going to have to at a minimum write it to a temporary file locally. That’s because whether you use fopen() or curl to access the file you are going to need some way to write the stream to Amazon. I’m not sure of a way to program a stream that essentially connects the remote file directly to S3. In fact, it’s theoretically impossible as S3 cannot execute scripts and the image cant run a script.
You could load the image through some form of stream buffer if you are looking to minimize the amount of information stored in memory, but writing it to a temporary file should be the easiest thing. If you run out of space because you have so many users in the system you either upgrade to a large server or add another server under a load balancer. Personally, I use Amazon’s S3 PHP class on my system and move it from a temp file locally directly to S3 using a script like this one:
Clearly this isn’t a robust script but figured I’d just share the path that I’ve gone down myself. I should add, as it seems your primary concern in this case would be processing power, check out this interesting post on resizing billions of images in the cloud. http://www.nslms.com/2010/11/01/how-to-resize-billions-of-images-in-the-cloud/
Update
According to this answer How best to resize images off-server “PHP/GD lets you send jpeg directly in http response.”