5

我正在使用 Amazon S3 放置 mp3 文件,然后允许我们的网站访问者从 Amazon AWS 下载 mp3。我使用 S3Fox 来管理文件,一切似乎都运行良好,直到最近我们收到很多访客抱怨 mp3 是通过浏览器流式传输的,而不是显示浏览器保存对话框。我尝试了一些 mp3,并注意到对于一些 mp3,会出现保存对话框,而对于其他一些,它们是通过浏览器流式传输的。我能做些什么来强制下载 mp3 文件而不是通过网络浏览器流式传输....

任何帮助将非常感激。谢谢

4

4 回答 4

9

为此,您需要设置 Content-Disposition 标头:

Content-disposition: attachment; filename=song.mp3

我认为这对于 S3Fox 是不可能的。您可以使用Bucket Explorer(不是免费的)或编写脚本来上传文件。

于 2010-05-19T10:54:38.030 回答
2

这最终成为我从 AWS S3 强制下载文件的解决方案。

在 safari 中,文件以 .html 文件的形式下载,直到我停止返回 readfile 并单独运行该函数。

  public function get_download($upload_id)
  {
    try {
      $upload = Upload::find($upload_id);
      if ($upload->deleted)
        throw new Exception("This resource has been deleted.");

      if ($upload->filename == '')
        throw new Exception("No downloadable file found.  Please email info@clouddueling.com for support.");

      header("Content-Description: File Transfer");
      header("Content-Type: application/octet-stream");
      header("Content-Disposition: attachment; filename={$upload->uploaded_filename};");

      readfile("https://s3.amazonaws.com/stackoverflow/uploads/" . $upload->filename);
      exit;
    } catch(Exception $e) {
      return $e->getMessage();
    }
  }
于 2013-04-10T15:33:37.210 回答
2

好的,你问这个问题已经很久了,但我遇到了同样的问题,我想与社区分享我的解决方案,以防其他人需要解决这个问题。当然,您可以从 Amazon S3 控制台更改 Content-Type 和 Content-Disposition,但有趣的是以编程方式进行。

以下代码对我来说很好:

require_once '../sdk-1.4.2.1/sdk.class.php';

// Instantiate the class
$s3 = new AmazonS3();

// Copy object over itself and modify headers
$response = $s3->copy_object(
    array( // Source
        'bucket' => 'your_bucket',
        'filename' => 'Key/To/YourFile'
    ),
    array( // Destination
        'bucket' => 'your_bucket',
        'filename' => 'Key/To/YourFile'
    ),
    array( // Optional parameters
        'headers' => array(
            'Content-Type' => 'application/octet-stream',
            'Content-Disposition' => 'attachment'
        )
    )
);

// Success?
var_dump($response->isOK()); 

希望它可以帮助其他在同样的麻烦中挣扎的人。

于 2011-10-01T18:37:20.353 回答
1

在 s3 管理控制台窗口中,右键单击并选择属性。

单击元数据。

点击添加更多元数据

键:内容处置值:附件

节省。就这样。

这是一张图片http://i.imgur.com/2PWK3xF.jpg

于 2016-09-23T10:44:33.610 回答