ds000001 2012-11-06 11:28
浏览 68
已采纳

允许用户将MP3上传到Amazon S3

I’m working on a website where users can upload podcasts. Podcasts are to be MP3 files, and stored in an Amazon S3 bucket.

What is the normal flow for this? I’ve Googled, but any articles relating to file uploads tend to be using the Amazon client libraries, and ideally I don’t want to use PHP (I’m using the LAMP stack) for uploading an MP3 file due to timeouts, file size limits etc.

Is there a way around this?

  • 写回答

4条回答 默认 最新

  • dongzhe3573 2012-11-22 10:37
    关注

    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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加