2013-11-26 103 views
0

我使用亚马逊S3 php来上传和下载文件。下载私人对象amazon s3 api

用于为例摆脱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; 
} 

下载它

但这是服务器很重,有没有解决方案直接从亚马逊s3使用链接下载私人对象,有点像公共对象与安全。

+0

[Amazon S3上的隐私]的可能重复(http://stackoverflow.com/questions/20187441/privacy-on-amazon-s3) –

回答

1

您可以为具有到期日期的对象创建预先签名的URL。您可以使用此功能允许用户直接从Amazon S3下载私人对象。适用于PHP的AWS开发工具包有一个简单的S3Client::getObjectUrl() method,可以帮助您做到这一点。