We upload contents to S3 private bucket. After uploading contents we access them through presigned url. MP4, images are working fine when we access that url through the browser. But when we try to access SWFs and PDFs, browser prompts to download content. And also it won't happen when we try to access assets from public bucket.
我们将内容上传到S3私人桶。上传内容后,我们通过预先签名的URL访问它们。 MP4,当我们通过浏览器访问该URL时,图像正常工作。但是当我们尝试访问SWF和PDF时,浏览器会提示下载内容。当我们尝试从公共存储桶访问资产时也不会发生这种情况。
Is it default behavior or is there any solution for that?
它是默认行为还是有任何解决方案?
I check this doc
我查看这个doc
code to get url
获取网址的代码
public function getPresignedUrl($filename, $expires,$bucket=NULL)
{
if($bucket==NULL){
$bucket=$this->bucket;
}
$command = $this->getClient()->getCommand('GetObject', ['Bucket' =>$bucket , 'Key' => $filename]);
$request = $this->getClient()->createPresignedRequest($command, $expires);
return (string) $request->getUri();
}
=============================Update 1=================================
=============================更新1 =================== ==============
We are using 'upload' function of AWS sdk to upload swfs, pdfs and also mp4s.
我们使用AWS sdk的“上传”功能上传swfs,pdfs和mp4s。
public function upload($filename, $source, $acl = null, array $options = [])
{
if($this->getClient()->upload(
$this->bucket,
$filename,
$source,
!empty($acl) ? $acl : $this->defaultAcl,
$options
)){
return true;
}else{
return false;
}
}
Thanks
谢谢
2 个解决方案
#1
1
When uploading the file, S3 Client will try to determine the correct content type if one hasn't been set . If no content type is provided and cannot be determined by the filename, the default content type, "application/octet-stream"
, will be used, thus the browser promts you to download the file.
上传文件时,如果尚未设置,则S3 Client将尝试确定正确的内容类型。如果没有提供内容类型且无法通过文件名确定,则将使用默认内容类型“application / octet-stream”,因此浏览器会提示您下载该文件。
have a look at http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
看看http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
$s3->create_object($bucket, $file_name, array(
// other things
'contentType' => 'application/pdf',
));
#2
0
As Vamsi said, I upload content with mime type was fixed my issue.
正如Vamsi所说,我上传内容与mime类型修复了我的问题。
public function uploadPut($filename, $source, $acl = null,$mime=null,$storage='REDUCED_REDUNDANCY', array $options = []){
$result = $this->getClient()->putObject(array(
'Bucket' => $this->bucket,
'Key' => $filename,
'SourceFile' => $source,
'ContentType' => $mime,
'ACL' => $acl,
'StorageClass' => $storage,
));
}
call function
通话功能
uploadPut($file->name, $file->name, null, $file->mimeType);
#1
1
When uploading the file, S3 Client will try to determine the correct content type if one hasn't been set . If no content type is provided and cannot be determined by the filename, the default content type, "application/octet-stream"
, will be used, thus the browser promts you to download the file.
上传文件时,如果尚未设置,则S3 Client将尝试确定正确的内容类型。如果没有提供内容类型且无法通过文件名确定,则将使用默认内容类型“application / octet-stream”,因此浏览器会提示您下载该文件。
have a look at http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
看看http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
$s3->create_object($bucket, $file_name, array(
// other things
'contentType' => 'application/pdf',
));
#2
0
As Vamsi said, I upload content with mime type was fixed my issue.
正如Vamsi所说,我上传内容与mime类型修复了我的问题。
public function uploadPut($filename, $source, $acl = null,$mime=null,$storage='REDUCED_REDUNDANCY', array $options = []){
$result = $this->getClient()->putObject(array(
'Bucket' => $this->bucket,
'Key' => $filename,
'SourceFile' => $source,
'ContentType' => $mime,
'ACL' => $acl,
'StorageClass' => $storage,
));
}
call function
通话功能
uploadPut($file->name, $file->name, null, $file->mimeType);