Cl'*_*Cl' 57 amazon-s3 amazon-web-services
出于某种原因,我的S3存储桶中的文件被强制作为下载而不是内联显示,因此如果我复制图像链接并将其粘贴到地址栏然后导航到它,它将促使我的浏览器下载它.相反,我实际上必须点击打开图像才能转到网址.
有任何方法可以改变从S3提供文件的方式
gre*_*aty 41
您需要更改Content-Type.在S3控制台中,右键单击该对象,然后选择"属性",然后选择"元数据"下的"属性".您也可以通过编程方式执行此操作:http://docs.amazonwebservices.com/AWSSDKforPHP/latest/index.html#m=AmazonS3/change_content_type
Neo*_*Neo 36
$client->putObject(array(
'Bucket' => 'buckname',
'Key' => $destination,
'SourceFile' => $source,
'ContentType' =>'image/jpeg', //<-- this is what you need!
'ACL' => 'public-read'//<-- this makes it public so people can see it
));
Run Code Online (Sandbox Code Playgroud)
Ant*_*ley 13
如果您使用的是python,则可以按如下方式设置ContentType
s3 = boto3.client('s3')
mimetype = 'image/jpeg' # you can programmatically get mimetype using the `mimetypes` module
s3.upload_file(
Filename=local_path,
Bucket=bucket,
Key=remote_path,
ExtraArgs={
"ContentType": mimetype
}
)
Run Code Online (Sandbox Code Playgroud)
您也可以在 aws cli 中实现相同的功能。注意*.jpeg检查s3文档
aws s3 cp \
--exclude "*" \
--include "*.jpeg" \
--content-type="image/jpeg" \
--metadata-directive="REPLACE" \
--recursive \
--dryrun \
s3://<bucket>/<path>/ \
s3://<bucket>/<path>/
Run Code Online (Sandbox Code Playgroud)
或者,如果您想一次修改一个对象,您可能需要使用s3api copy-object
aws s3api copy-object \
--content-type="image/jpeg" \
--metadata-directive="REPLACE" \
--copy-source "<bucket>/<key>" \
--bucket "<bucket>" \
--key "<key>" \
--acl public-read
Run Code Online (Sandbox Code Playgroud)
您还需要为内联而不是附件指定内容处置。
$client->putObject(array(
'Bucket' => 'buckname',
'Key' => $destination,
'SourceFile' => $source,
'ContentType' =>'image/jpeg', //<-- this is what you need!
'ContentDisposition' => 'inline; filename=filename.jpg', //<-- and this !
'ACL' => 'public-read'//<-- this makes it public so people can see it
));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
35378 次 |
| 最近记录: |