0
votes

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.

Is it default behavior or is there any solution for that?

I check this 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=================================

We are using 'upload' function of AWS sdk to upload swfs, pdfs and also 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

2 Answers

1
votes

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.

have a look at http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html

$s3->create_object($bucket, $file_name, array(
                // other things
                'contentType' => 'application/pdf',

));
0
votes

As Vamsi said, I upload content with mime type was fixed my issue.

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