如何解决如何强制 Google 存储文件具有 `content-disposition: inline` 而不是 `attachment`?
我正在使用 GoogleApi.Storage.V1.Api.Objects.storage_objects_insert_simple 将文件上传到 Google Storage。但是,似乎无论我做什么,content-disposition
HTTP 响应标头都被设置为 attachment
,这会强制浏览器下载文件而不是在浏览器选项卡中显示它。
这是我的用法:
{:ok,object} =
GoogleApi.Storage.V1.Api.Objects.storage_objects_insert_simple(
gconn,"my-uploads-bucket","multipart",%{
name: Path.basename(path),contentType: content_type,contentdisposition: "inline" # <-- this doesn't seem to have an effect
},path
)
有谁知道如何强制内容处置标头的值为 inline
?
更新
在检查 object
的值后,我看到以下内容:
%GoogleApi.Storage.V1.Model.Object{
acl: nil,bucket: "my-uploads-bucket",cacheControl: nil,componentCount: nil,contentdisposition: "inline",# <-- !!!
contentEncoding: nil,contentLanguage: nil,contentType: "image/png",crc32c: "MGa01Q==",...
但是,通过 curl -I <url>
获取文件后,我看到以下内容:
HTTP/2 200
...
content-type: image/png
content-disposition: attachment
...
解决方法
我的错误似乎是使用 mediaLink 字段作为 URL。此 URL 甚至将下载作为 URL 的一部分:https://storage.googleapis.com/download/storage/....
如果我改为使用 name 字段来构建 URL,那么它会按预期工作。
send_resp(
conn,200,"https://storage.googleapis.com/my-bucket/" <> object.name
)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。