After lots of Googling, and back-and-forth on both the GitHub repository and Amazon documentation for the new PHP SDK, I’ve got a solution using Amazon’s new PHP SDK to generate the form fields, and Uploadify to actually upload the file directly to Amazon, bypassing my server. The code looks a little 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>