0

I'm using GoogleApi.Storage.V1.Api.Objects.storage_objects_insert_simple to upload files to Google Storage. However, it seems that no matter what I do, the content-disposition HTTP response header is being set to attachment which forces browsers to download a file rather than displaying it in a browser tab.

Here's my usage:

{: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
  )

Does anyone know how to force the content disposition header to have a value of inline?

Update

After inspecting the value of object, I'm seeing the following:

%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==",
  ...

However, after fetching a file via curl -I <url>, I see the following:

HTTP/2 200 
...
content-type: image/png
content-disposition: attachment
...
Raphael Rafatpanah
  • 19,082
  • 25
  • 92
  • 158
  • 1
    Do you get the same behavior even after forcing the `Content-Disposition` metadata with [gsutil](https://cloud.google.com/storage/docs/gsutil/commands/setmeta)? There is at least [this reference](https://stackoverflow.com/questions/42286724/google-cloud-storage-signed-url-forced-response-disposition) for issues between that specific header and at least Signed URLS (that I believe you are not using) that I believe you might find useful. – Daniel Ocando Jan 22 '21 at 10:23
  • 1
    It might be an issue with the library itself though. In which case I recommend you to open an issue [here](https://github.com/googleapis/elixir-google-api/tree/master/clients/storage). – Daniel Ocando Jan 22 '21 at 10:32
  • @DanielOcando Thank you for your responses. I'm not using Signed URLs because these URLs should be accessible to anyone who has the URL and no authentication is required. Is it possible that there is some configuration needed within Google Cloud to set the content disposition header to `inline`? – Raphael Rafatpanah Jan 23 '21 at 13:46
  • 1
    If you use `gsutil setmeta -h "Content-Disposition: inline" gs://[YOUR-BUCKET]/[YOUR-OBJECT]` do you still get this behavior? As advised [here](https://cloud.google.com/storage/docs/gsutil/addlhelp/TopLevelCommandLineOptions#options) the value for the Content-Disposition header is stored as object metadata and used in future requests on the object. – Daniel Ocando Jan 25 '21 at 12:00
  • So, it seems like my mistake here was in using the `mediaLink` field as the URL. This URL even has `download` as part of the URL: `https://storage.googleapis.com/download/storage/...`. If I instead use `name` field to build the URL, then it works as expected – Raphael Rafatpanah Jan 25 '21 at 22:57

1 Answers1

1

It seems like my mistake here was in using the mediaLink field as the URL. This URL even has download as part of the URL: https://storage.googleapis.com/download/storage/....

If I instead use name field to build the URL, then it works as expected.

send_resp(
  conn,
  200,
  "https://storage.googleapis.com/my-bucket/" <> object.name
)
Raphael Rafatpanah
  • 19,082
  • 25
  • 92
  • 158