rustypaste icon indicating copy to clipboard operation
rustypaste copied to clipboard

Forced download link on MIME override file

Open Nbelles opened this issue 3 years ago • 2 comments
trafficstars

Hello,

Is there a way to force the file to be downloaded when a file type has the MIME override enabled for that type? I want to be able to share the link to a file that would play in the browser (like .mp4) but also share a link that will auto-download as well (like with a flag in the URL or something similar). I thought I had seen this feature somewhere in this project but can't seem to find any documentation on it if it does exist.

Thanks!

Nbelles avatar Aug 28 '22 15:08 Nbelles

Hello!

This feature currently does not exist. You can only override the MIME types and file will be previewed or downloaded based on your browser settings. However, what you have suggested sounds interesting. Do you mean like a ?download=1 flag/parameter in the URL?

orhun avatar Aug 29 '22 14:08 orhun

Gotcha. That's precisely what I'm talking about though. It would be nice to add that kind of flag to the URL to temporarily override any overrides (haha) that might be in place.

Nbelles avatar Aug 29 '22 14:08 Nbelles

Hey, I implemented this in 99ac6156a8eafadee09fcba978f8353f4e9829ed

$ curl -s -o /dev/null -w '%{content_type}\n' $server/file.txt

text/plain; charset=utf-8

And when you specify download=true:

$ curl -s -o /dev/null -w '%{content_type}\n' $server/file.txt?download=true

application/octet-stream

This will force the browser to download the file.

Hope this helps! 🐻

orhun avatar Jan 31 '23 18:01 orhun

Just a random question: Is this expected to be cross-browser thing? On my test the file is downloaded on chrome but firefox insists on playing it: example

seqizz avatar Mar 29 '23 14:03 seqizz

I don't have Firefox but wanted to add that I have tested it working on Safari

Nbelles avatar Mar 29 '23 14:03 Nbelles

Just a random question: Is this expected to be cross-browser thing? On my test the file is downloaded on chrome but firefox insists on playing it: example

Yeah I got the same result. The content type seems to be correct (application/octet-stream) so I'm not sure what is happening there.

orhun avatar Mar 29 '23 15:03 orhun