Shrine: How do you change the downloaded filename of a version?

Created on 29 Jan 2019  路  2Comments  路  Source: shrinerb/shrine

My website allows for document uploads. My original file downloads as the original uploaded filename, but I can't seem to change the filename of a processed version.

Below is the metadata of an example document record:
{"original":{"id":"document/58/doc/original-531c2e3313b7da078ec8d53d618dcf57.docx","storage":"store","metadata":{"size":33987,"filename":"test.docx","mime_type":"application/vnd.openxmlformats-officedocument.wordprocessingml.document"}},"converted":{"id":"document/58/doc/converted-3527847e1d1e55bc5255f04a3b1685f0","storage":"store","metadata":{"filename":null,"size":20534,"mime_type":null}}}

document[:original].url creates a url that allows me to download the file as test.docx from s3 at document/58/doc/original-531c2e3313b7da078ec8d53d618dcf57.docx

But document[:converted].url creates a url that only downloads the file as converted-3527847e1d1e55bc5255f04a3b1685f0.zip from s3 document/58/doc/converted-3527847e1d1e55bc5255f04a3b1685f0

Most helpful comment

Shrine will set the "download filename" automatically on upload if the filename is specified (via the :content_disposition option). If an S3 object didn't have a download filename specified on upload, you can still specify it when generating URL via the :response_content_disposition URL option:

document[:converted].url(response_content_disposition: ContentDisposition.attachment("my-filename.docx"))

The above uses the content_disposition gem, which is a Shrine dependency as of version 2.14, and automatically required by S3 storage.

I will close the issue, as this is a usage question, but let me know whether it worked, and if it didn't we can find another solution on the Google Group thread.

All 2 comments

See this thread: https://groups.google.com/forum/#!searchin/ruby-shrine/download$20filename%7Csort:date/ruby-shrine/mgZff33NkJI/kZmP59sXCAAJ

As noted in our readme and issue form, we prefer help questions are asked in our ruby-shrine Google Group. We want issues for bug reports. It makes it easier for tracking otherwise the bug reports will get buried in the noise.

Shrine will set the "download filename" automatically on upload if the filename is specified (via the :content_disposition option). If an S3 object didn't have a download filename specified on upload, you can still specify it when generating URL via the :response_content_disposition URL option:

document[:converted].url(response_content_disposition: ContentDisposition.attachment("my-filename.docx"))

The above uses the content_disposition gem, which is a Shrine dependency as of version 2.14, and automatically required by S3 storage.

I will close the issue, as this is a usage question, but let me know whether it worked, and if it didn't we can find another solution on the Google Group thread.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Grafikart picture Grafikart  路  4Comments

uurcank picture uurcank  路  10Comments

jakehockey10 picture jakehockey10  路  6Comments

technodrome picture technodrome  路  4Comments

Sohair63 picture Sohair63  路  3Comments