Reputation: 39
I am successful in uploading to amazon s3 bucket using post and swf upload but can any one tell me how to upload to a subdirectory inside my bucket.
I am using php as my server side language.
Thanks in advance
Upvotes: 0
Views: 1968
Reputation: 11
For nesting files on bucket's subfolder I first created subfolder via PHP as below:
if(!($s3->if_object_exists($S3_BUCKET, 'mysubfolder/'))) {
$s3->create_object($S3_BUCKET,'mysubfolder/', array('body' => ''));
};
then with SWFUPLOAD via javascript code in the post_params array I appended on key value the name of my nested subfolder as follows:
post_params: {"AWSAccessKeyId":"AXAXAXAXAX", "key":"mysubfolder/${filename}", "acl":"public-read", "policy":"SAgXQ0KCX0=","signature":"QvbfiUUsRby8wovt=","success_action_status":"201", "content-type":"image/"}
Another code segment. check where is uppercase letters
/********************************* PHP CODE */
if(!($s3->if_object_exists($S3_BUCKET, 'mysubfolder/'))) {
$s3->create_object($S3_BUCKET,'IMAGES/', array('body' => ''));
};
....
/********************************** JAVASCRIPT CODE */
post_params: {"AWSAccessKeyId":"AXAXAXAXAX", "key":"IMAGES/${filename}", "acl":"public-read", "policy":"SAgXQ0KCX0=","signature":"QvbfiUUsRby8wovt=","success_action_status":"201", "content-type":"image/"}
Upvotes: 1
Reputation: 238667
You may find this article helpful:
http://www.flynsarmy.com/2011/03/upload-to-amazon-s3-with-uploadify/
It's using Uploadify instead of the SWFUpload library (but I think Uploadify uses the SWFUpload library internally). Regardless, the concept is still the same. You need to include the folder in your policy and request.
Upvotes: 0
Reputation: 690
you should include the file path in your policy and post parameters. for example, when setting your policy array, set the key of the file to be "/path/../filename.ext".
array("starts-with", '$key', $this->file_key);
use that in the key in post parameters
Upvotes: 2
Reputation: 4448
i got the same problem as well, it seems amazon s3 doesn't have folder concept, the workaround most people suggest is create a object with names like folder/test.txt.
Upvotes: 0
Reputation: 11546
If you're using the php-aws library, there's really not much to it:
$S3 = new S3(AWS_KEY, AWS_SECRET);
$from = 'fileonyourserver.ext';
$to = '/path/to/place/in/inside/bucket/.../file.ext';
if ($S3->putObject(AWS_BUCKET, $to, $from, true)){
//upload success
}
Upvotes: 0