AWS在S3存储桶中预先登记的url url
问题描述:
我们将内容上传到S3专用存储桶。上传内容后,我们通过预先登记的网址访问它们。 MP4,当我们通过浏览器访问该网址时,图像正常工作。但是,当我们尝试访问SWF和PDF时,浏览器会提示下载内容。 而且当我们尝试从公共存储区访问资产时也不会发生。AWS在S3存储桶中预先登记的url url
它是默认行为还是有任何解决方案吗?
我检查这个doc
代码来获取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();
}
=========================== ==更新1 =================================
我们使用AWS的'上传'功能sdk上传swfs,pdf和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;
}
}
感谢
答
当上传文件,S3客户端将尝试确定正确的内容类型,如果没有设置。 如果没有提供内容类型并且不能通过文件名确定,则将使用默认内容类型"application/octet-stream"
,因此浏览器会提示您下载该文件。
看看http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
$s3->create_object($bucket, $file_name, array(
// other things
'contentType' => 'application/pdf',
));
答
正如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,
));
}
通话功能
uploadPut($file->name, $file->name, null, $file->mimeType);
谢谢。我会检查这一点,并让你知道。 – cha
我已经更新了这个问题。我们正在使用AWS sdk的上传功能。该函数中没有涉及mime类型,但将函数接受为mime类型 – cha