简体   繁体   English

下载私有对象Amazon S3 API

[英]Download private objects amazon s3 api

I'm using amazon S3 php to upload and download files. 我正在使用Amazon S3 php上传和下载文件。

for exemple to get a private file from amazon s3 I'm using: 例如从amazon s3获取私有文件,我正在使用:

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

and

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;
}

TO download it 下载

but this is very heavy for the server, is there a solution to directly download private objects from amazon s3 using a link, a little like for public objects with a security. 但这对于服务器来说非常繁重,是否有一种解决方案可以使用链接直接从amazon s3下载私有对象,有点像具有安全性的公共对象。

You can create pre-signed URLs for objects that have an expiration date. 您可以为具有到期日期的对象创建预签名的URL。 You can use this feature to allow people to download private objects directly from Amazon S3. 您可以使用此功能允许人们直接从Amazon S3下载私有对象。 The AWS SDK for PHP has an easy S3Client::getObjectUrl() method that can help you do this. 适用于PHP的AWS开发工具包具有一个简单的S3Client::getObjectUrl()方法 ,可以帮助您执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM