tags:

views:

414

answers:

1

Hello, I am trying to figure out if "Content-Disposition:attachment; filename=file_name" is required or not when file is sent as an attachment, and I am interested to persist it by the original name on a storage (drive). It looks like this is the only way to retrieve the original file name, but RFC is so muddy on it (link to RFC). It uses words such as "should" and not "must". WIKI (link to WIKI) says it better, but it's not RFC I can take to the client. Ideas?

+1  A: 

The header is optional, of course, but including it is a good idea if you do have a preference for

  • whether the file should be showed inline or saved as an attachment, or
  • what the suggested filename should be if it is saved as an attachment

The browser or user-agent is not bound by this header, but treats it as a suggestion. The actual behaviour of the browser can be complex, but typically, in absense of this header a browser will decide on an appropriate course of action primarily based on its Mime type, and if it is an unrecognised Mime type it will usually default to saving as an attachment.

Using the Content-Disposition header gives you control in the following cases

  • You are sending something which has a Mime type that the recipient's browser CAN display inline, but you would prefer it not to, and to offer it as a download instead.
  • You are sending something which may be saved to disk by the recipient, and you would like to specify what the filename should default to when it is saved. Without this information, the browser will typically make up a filename based on the URL, which may not be a sensible one (for example, if serving everything from a script, you don't want it to be the name of the script).
thomasrutter