Viewing PDF in browser - instead of downloading. (Shrine 2.9.0)

Hi, I want to change the behaviour of a link to a shrine attachment from downloading to opening in the browser (where supported). This is for a PDF file.

Currently I’m using shrine 2.9.0 (I’ve not had time to migrate to newer) with the S3 plugin. calling attachmnent.url generates a presigned url that triggers the download. The file name is also currently the object key instead of the actual file name, I’d like to fix that as well.

From what I can tell, I ought to be able to just do attachment.url(response_content_disposition: "inline").

But this isn’t working.

Any advice?

Hmm it occurred to me examine the response headers in dev tools:

I’m seeing:
Content-Type: binary/octet-stream

While a working link is:
Content-Type: application/pdf

So I tried:

attachment.url(response_content_disposition: "inline", response_content_type: "application/pdf")

But still I see Content-Type: binary/octet-stream in the response headers.

I solved the issue. I had written my own #url method on the model (referred to as attachment.url above), and that url method wasn’t forwardding options passed to shrines url method.

Sorry for the added noise. =)

1 Like