Mobile app version of vmapp.org
Login or Join
BetL925

: PDF download fails because of...what? On trying to download a pdf file my Firefox downloads a file without file ending and means it would be an application/octet-stream file: Only after a manually

@BetL925

Posted in: #Assets #Download #FileExtension #Pdf #Transfer

On trying to download a pdf file my Firefox downloads a file without file ending and means it would be an application/octet-stream file:



Only after a manually add to the file the ending pdf i become able to open it with usual tools.

The questions are:


on which side is a problem? On my or on the administrator of the site, where i download the file?
In both cases: what is exactly wrong?


My guess was, the site administrator wanted to force users to download his pdf files, instead of open them in browser, with something like this setting:

AddType application/octet-stream .pdf


But where the file ending is remains the dark secret for me.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @BetL925

2 Comments

Sorted by latest first Latest Oldest Best

 

@Jamie184

PDF download fails ...


By the sound of it, the PDF download isn't "failing", it's just not being saved with a .pdf file extension. This is probably only a "problem" on Windows, that requires the file extension in order to determine the file type. As I understand it, Mac users will still be able to open the file without issue.

The fact that the file is being saved without an extension implies the URL linking to the file is also without the appropriate file extension.

You can (as a user) improve this situation by configuring your browser to always prompt for file downloads (recommended, although rarely the default configuration) - you can then simply rename the file in the "Save As..." dialogue (which I would often do anyway, as downloaded files are rarely named how you would like them to be).


AddType application/octet-stream .pdf



It is arguably incorrect behaviour to force a file download by setting the mime-type to application/octet-stream. This is very outdated in my opinion. This is simply a mime-type that the browser is probably unable to open, so as a last resort offers it for download in the hope that you know what to do with it.

The "correct" way to force a download would be to still set the correct mime-type (ie. application/pdf in the case of PDF files) but to also set the Content-Disposition: attachment; ... HTTP response header (as @Stephen suggests). It is the attachment part that forces a download in all modern browsers and the Content-Disposition header also always the "website" to set a recommended file name when the URL could be set to something completely different (this is still editable if you have the browser "prompt" for file downloads).

10% popularity Vote Up Vote Down


 

@BetL925

To get the .pdf extension on the file after download, it needs an HTTP header like:

Content-Disposition: attachment; filename=some-file.pdf;


With this header it will be saved as some-file.pdf even if served from the URL /pdf-download.php

See on StackOverflow: How to Use Content-disposition for force a file to download to the hard drive?

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme