【问题标题】:AWS presigned url for assests in S3 bucketS3 存储桶中资产的 AWS 预签名 URL
【发布时间】:2017-02-16 03:51:27
【问题描述】:

我们将内容上传到 S3 私有存储桶。上传内容后,我们通过预签名的 url 访问它们。 MP4,当我们通过浏览器访问该 URL 时,图像工作正常。但是当我们尝试访问 SWF 和 PDF 时,浏览器会提示下载内容。 当我们尝试从公共存储桶访问资产时,它也不会发生。

这是默认行为还是有任何解决方案?

我检查了这个doc

获取网址的代码

    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 的“上传”功能来上传 swf、pdf 和 mp4。

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

谢谢

【问题讨论】:

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


    【解决方案1】:

    上传文件时,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',
    
    ));
    

    【讨论】:

    • 谢谢。我会检查一下并告诉你。
    • 我已经更新了这个问题。我们正在使用 AWS sdk 的上传功能。该函数不涉及 mime 类型,但 put 函数接受 mime 类型
    【解决方案2】:

    正如 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);
    

    【讨论】:

      猜你喜欢
      • 2019-01-27
      • 2015-11-22
      • 2021-01-30
      • 2020-11-29
      • 2019-01-30
      • 1970-01-01
      • 2019-11-16
      • 2022-01-27
      • 1970-01-01
      相关资源
      最近更新 更多