我正在尝试为我在 php 中使用 s3 api 上传的文件设置内容类型元数据。我的代码如下所示:
$upload_model = $s3->createMultipartUpload(array("Bucket" => $bucket , "Key"=> $key, "ACL"=>$acl , "Metadata" => array('Content-Type' => $this -> get_file_type($file_path) ) ) );
假设我有“video/webm”内容类型,我在 s3 浏览器中看到的结果是“Content-Type”设置为“binary/octet-stream”并且 s3 创建了一个“x-amz-meta” -content-type”,里面有“video/web”值,这对我来说完全没用。因为浏览器仅响应“Content-Type” header 来决定是下载文件还是在浏览器中显示文件。
最佳答案
我发现了问题,这是一种误解。 Content-Type 元数据在 createMultipartUpload 函数中有自己的参数。所以这段代码工作得很好:
$s3->createMultipartUpload(array("Bucket" => $bucket , "Key"=> $key, "ACL"=>$acl , "ContentType" => $this -> get_file_type($file_path) ) );
我对此一无所知,但似乎您为元数据 s3 提供的任何名称都会在其中添加一个 x-amz-meta 前缀,以表明它是用户定义的元数据。
关于php - 在 s3 分段上传上设置内容类型元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17535301/