1001Ferramentas
📄Dev

Content-Disposition Filename Parser

Pulls the download filename out of a Content-Disposition header, preferring the percent-encoded filename* form from RFC 5987 and decoding it for you.

Filename

Which filename the browser will actually use

When a download saves under a strange name — full of percent signs, or turning into "download" with no extension — the cause is almost always the Content-Disposition header. It carries the suggested name in two formats that coexist: the traditional filename, limited to ASCII, and the RFC 5987 filename*, which declares its encoding and allows accents, Cyrillic or kanji.

Paste the whole header and the page shows which name will be used. When filename* is present it wins — that is the rule browsers follow — and the value appears already decoded, so "relat%C3%B3rio.pdf" reads as "relatório.pdf" again. When only the plain filename exists, that is what shows up, with the quotes stripped.

The practical advice is to send both: a plain filename with an unaccented version for older clients, and filename*=UTF-8''… with the real name. It also pays to check what comes before the name: attachment forces a download, while inline asks the browser to display the content when it knows how. And a filename coming from user input needs sanitising — slashes, quotes and line breaks in a header are a well-known attack vector.

Frequently asked questions

Why did my filename arrive with %C3%A9 in it?
Because the value was percent-encoded but delivered in the plain filename, which has no way to declare an encoding — so the client reads the characters literally. The correct form is filename*=UTF-8''name%20with%20accent.pdf, which states explicitly that this is percent-encoded UTF-8.
What are the two single quotes in filename* for?
The format is charset'language'value. The middle field is optional and almost always left empty, which produces that UTF-8'' with two quotes together. It is not a typo: it is an empty language field.
Does the page read headers split across several lines?
No. RFC 2231 allows a long parameter to be split into filename*0, filename*1 and so on, and those pieces are not reassembled here — in practice modern servers do not use that form for filenames, and current browsers do not expect it either.

Related Tools