下载私人物品amazon s3 api

时间:2013-11-26 22:13:17

标签: php amazon-web-services amazon-s3

我正在使用amazon S3 php上传和下载文件。

例如从亚马逊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直接下载私有对象,有点像具有安全性的公共对象。

1 个答案:

答案 0 :(得分:1)

您可以为具有过期日期的对象创建预签名URL。您可以使用此功能允许人们直接从Amazon S3下载私有对象。 AWS SDK for PHP有一个简单的S3Client::getObjectUrl() method,可以帮助您实现这一目标。