Allows user to upload MP3s to Amazon S3

Im working on a website where users can download podcasts. Podcasts must be MP3 files and stored in an Amazon S3 bucket.

What is the normal flow for this? Ive googled, but any articles regarding file uploads tend to use Amazon client libraries, and ideally I don't want to use PHP (Im using the LAMP stack) to download an MP3 file due to timeouts, file size limitations, etc. .d.

Is there any way around this?

+6
source share
4 answers

After much Googling and back-and-forth both in the GitHub repository and in the Amazon documentation for the new PHP SDK, Ive got a solution using the new Amazon SDK for creating form fields and Uploadify to actually upload the file directly to Amazon, bypassing mine server. The code looks something like this:

<?php $bucket = (string) $container['config']->images->amazon->bucket; $options = array( 'acl' => CannedAcl::PUBLIC_READ, 'Content-Type' => 'audio/mpeg', 'key' => 'audio/a-test-podcast.mp3', 'success_action_redirect' => (string) $container['config']->main->base_url . 'upload/success/', 'success_action_status' => 201, 'filename' => '^' ); $postObject = new PostObject($container['amazon_s3'], $bucket, $options); $postObject->prepareData(); $formAttributes = $postObject->getFormAttributes(); $formInputs = $postObject->getFormInputs(); $uploadPath = $formAttributes['action']; ?> <script> (function($) { $('#podcast').uploadify({ 'buttonClass': 'button', 'buttonText': 'Upload', 'formData': <?php echo json_encode($formInputs); ?>, 'fileObjName': 'file', 'fileTypeExts': '*.mp3', 'height': 36, 'multi': false, 'onUploadError': function(file, errorCode, errorMsg, errorString) { console.log('onUploadError', file, errorCode, errorMsg, errorString); }, 'onUploadSuccess': function(file, data, response) { console.log('onUploadSuccess', file, data, response); }, 'swf': '/assets/cms/swf/uploadify.swf', 'uploader': '<?php echo $uploadPath; ?>', 'width': 120 }); })(jQuery); </script> 
+1
source

Amazon S3 supports direct downloads . It may be an option here. To implement PHP check this post .

+4
source

You do not need to worry about file size, although you are using php, you can set up file size limits and performance limits in php.ini , and php libraries for s3 will reduce your work. You can start with this guide .

0
source

Requests to S3 must be signed with a valid secret key and always include authorization. You can do this on the client side using JavaScript in theory, but this will be due to Ajax calls to sign the headers if you do not want to reveal your secret key on the client side. Another issue will be browser compatibility. You will have to use file splitting and calculate checksums for large files available in all modern browsers.

A simpler method would be a server-side solution with PHP or any other server-side scripting language.

0
source

All Articles