2015-06-25 43 views
0

我在這裏有一個網站http://www.voclr.it/acapellas/我的文件託管在我的Amazon S3帳戶上,但是當訪問者從我的網站上下載MP3時,它迫使他們流式傳輸它,但我真正希望它做的是下載它到那裏桌面。S3 Force Download

我現在在網站上禁用了S3,所以下載工作正常。但真的我想S3搜索MP3

回答

0

基本上,你必須告訴S3覆蓋響應的content-disposition標題。您可以通過將response-content-disposition查詢字符串參數附加到S3文件url並將其設置爲所需的content-disposition值來實現此目的。要強制下載,請嘗試:

<url>&response-content-disposition="attachment; filename=somefilename" 

您可以在S3 docs中找到它。有關content-disposition標題可以假設的值的信息,您可以查看here

作爲附加信息,這也適用於Google雲端存儲。

0
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()); 

Amazon AWS S3 to Force Download Mp3 File instead of Stream It

+0

我在哪裏可以把這個代碼? –