簡體   English   中英

下載私有對象Amazon S3 API

[英]Download private objects amazon s3 api

我正在使用Amazon S3 php上傳和下載文件。

例如從amazon s3獲取私有文件,我正在使用:

// Cast the body to a primitive string
$bodyAsString = (string) $object['Body'];

public function getResponse($content, $filename, $length, $contentType)
{
    $response = new Response();

    $response->headers->set('Content-Description','File Transfer');
    $response->headers->set('Content-Type',$contentType);
    $response->headers->set('Content-Disposition','attachment; filename='.basename($filename));
    $response->headers->set('Content-Transfer-Encoding','binary');
    $response->headers->set('Expires','0');
    $response->headers->set('Cache-Control','must-revalidate');
    $response->headers->set('Pragma','public');
    $response->headers->set('Content-Length',$length);

    $response->setContent($content);

    return $response;
}

下載

但這對於服務器來說非常繁重,是否有一種解決方案可以使用鏈接直接從amazon s3下載私有對象,有點像具有安全性的公共對象。

您可以為具有到期日期的對象創建預簽名的URL。 您可以使用此功能允許人們直接從Amazon S3下載私有對象。 適用於PHP的AWS開發工具包具有一個簡單的S3Client::getObjectUrl()方法 ,可以幫助您執行此操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM