Richard Torcato
Richard Torcato

Reputation: 2762

uploading to S3 subdirectories with plupload

i have plupload uploading to amazon s3 with php, but I don't want to upload only to the root of the bucket. I want to save files in subdirectories. How do i save files to a buckets' subdirectories? i tried this:

multipart_params: {
  <?
              'key': '/imagegallery/${filename}', // use filename as a key
              'Filename': '/imagegallery/${filename}', // adding this to keep consistency across the runtimes
              'acl': 'public-read',
              'success_action_status': '201',
              'Content-Type': 'image/jpeg',
              'AWSAccessKeyId' : '<?php echo $accessKeyId; ?>',
              'policy': '<?php echo $policy; ?>',
              'signature': '<?php echo $signature; ?>'
},

that didn't work. It just placed the file in the root of the bucket. Do i need to add the directory to the policy file?

Upvotes: 0

Views: 387

Answers (2)

loveisbug
loveisbug

Reputation: 411

Amazon s3 doesn't have the concept of folder, some suggest creating key with name like "folder/test.txt' to get around it.

Upvotes: 0

simonl
simonl

Reputation: 11

You need to change the filename of the file you are uploading to contain the directory - s3 doesn't have directories as such - from the bundled s3.php example:

UploadFile: function(up, file) {
log('[UploadFile]', file);
up.settings.multipart_params.key = 'yourdirectory/'+file.name;

// You can override settings before the file is uploaded
// up.setOption('url', 'upload.php?id=' + file.id);
// up.setOption('multipart_params', {param1 : 'value1', param2 : 'value2'});
}

Upvotes: 1

Related Questions