Jonathan Clark
Jonathan Clark

Reputation: 20558

Upload to Amazon S3 with Codeigniter

I am developing an API using Codeigniter and I want to let users upload images to my Amazon S3 account. I am using Phils Restserver and Donovan Schönknecht S3 library (for Ci).

It works perfectly to upload a local file to Amazon but how can I get the image file sent via normal external form?

Using the built in Ci upload library it works fine but then I have to store the files locally on my own server and I want them on S3. Can the two be combined?

I guess what I am asking is how can I "get" the image file that is sent to the controller and resize it and then upload it to S3?

Do I perhaps need to temporary save it on the local server, upload it to S3 and then remove it from the local server?

This is my "upload" modal:

// Load the s3 library

$this->load->library('S3');

// Make the upload

if ($this->s3->putObjectFile($args['local'], "siticdev", $args['remote'], S3::ACL_PUBLIC_READ)) {

// Handle success

return TRUE;

} else {

// Handle failure

return FALSE;

}

Thankful for all input!

Upvotes: 2

Views: 5884

Answers (2)

jimbo2087
jimbo2087

Reputation: 1054

You should definitely check out the CI S3 library. The "spark" is available here - http://getsparks.org/packages/amazon-s3/versions/HEAD/show

Upvotes: 1

swatkins
swatkins

Reputation: 13640

If I understand you correctly, you want a user to upload an image via a form, resize that image, then transfer that to Amazon S3.

You'll have to store the file locally (at least for a few seconds) to resize it with CI. After you resize it, then you can transfer it to Amazon S3. In your success callback from the transfer, you can delete the image from your server.

Upvotes: 3

Related Questions