Force Downloading of File in Shrine 3
Usually we get link to file like this:
irb(main):001:0> Document.last.asset.url
=> "https://bucket-development.s3.amazonaws.com/store/document/1/asset/2ac6a0262aee19787dcf87075043afef.pdf"
But in this case, this file will be opened in browser.
If you want to force download file you should add response_content_disposition
and make private link (if it’s not true):
irb(main):002:0> Document.last.asset.url(public: false, response_content_disposition: "attachment")
=> "https://bucket-development.s3.amazonaws.com/store/document/1/asset/2ac6a0262aee19787dcf87075043afef.pdf?response-content-disposition=attachment&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAXXXXXXXXXXXXX%2F20201211%2Fus-west-3%2Fs3%2Faws4_request&X-Amz-Date=20201211T122731Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&X-Amz-Signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Discover More Reads
Categories: