Feature preview

Feature Introduction

Chinese characters in the file name are garbled when downloading attachments, why do the two file name parameters in the response header need to be written together

When downloading attachments, the Chinese file name is garbled, mostly because only filename or only filename* was written in the response header. The specification document states that both should be written together: parameters with an asterisk should be encoded in UTF-8 percentage encoding and have higher priority, while those without an asterisk should retain ASCII form for compatibility with old clients. This article also explains why the directory separator needs to be replaced.

Attachment download Response header

Feature Introduction

When downloading an attachment, the Chinese filename may display as garbled. The reason is usually not in the file itself, but in the Content-Disposition response header, which only wrote one filename parameter. The specification document is clear: the difference between filename and filename* lies in the fact that the latter uses the encoding defined in RFC 5987 Section 3.2, which is UTF-8 percent-encoding; when two parameters in the same field value exist and can be understood, the one with the asterisk takes precedence; for compatibility, it is recommended to write both together.

Which two parameters are for reading

The parameter with an asterisk solves the problem of 'how to safely express non-ASCII characters in the header', it encodes the Chinese name in UTF-8 and then escapes with percent signs, the browser decodes it to restore; the parameter without an asterisk takes on the role of a fallback, in terms of writing, it should replace non-ASCII characters with ASCII approximations, for example, replacing accented letters with plain letters, in the Chinese scenario, the original filename can be converted to pinyin or prefixed with English dates.

Write only the one without an asterisk, Chinese characters will be transmitted as garbage in some browsers; if the old client does not recognize this parameter, it will revert to the default name, and the user will get a string of names without a suffix, which is more麻烦。

Parameter Encoding method Priority The role assumed
filename ASCII approximate value Low Fallback name compatible with old clients
filename* UTF-8 percent encoding Both are used when available Accurately restore Chinese name

Why it is recommended not to use percent escaping in fallback parameters

There is a reminder that is easy to overlook in the document: Try to avoid using percent escape sequences in filenames without asterisks, as browsers handle them differently, some will decode and some will not. That is to say, the same header format will result in two different file names in two types of browsers, which can easily be misjudged as a program problem when troubleshooting.

The correct division of labor is: Place the content that needs to be escaped in parameters with asterisks, where the escaping is supported by specifications; only put readable ASCII names in the fallback parameters.

Why must the directory separator be replaced?

When a slash appears in the filename, improper handling can lead to directory traversal. A safe approach is to replace the path separators in the original name before generating the response header, and to handle fragments like「.」and「..」separately. Don't expect downstream components to do the purification for you.

This step and the validation on the upload side are two separate things: when uploading, it determines the directory where the file falls and the suffix with which it is saved, and when downloading, it determines the name displayed in the user's save dialog. Each layer manages a segment, and any laziness on any layer will be exposed.

What should be noted about the attachment link within the site.

For example, using content management systems like AnQiCMS, there are two entry points for attachments: one is the upload on the backend, and the other is through import interfaces like /api/import/archive for batch import with text resources. For the former, attention should be paid to the position of header concatenation usually in the download processing logic, and encoding should be explicitly specified instead of relying on the default value of the framework; for the latter, when batch importing, the original file name comes from the compressed package or table field, and it is even more important to complete the replacement of delimiters and rename handling before writing.

Since version 3.6.5, the background also supports uploading attachments as base64 encoded content through the interface. This path also needs to retain the original name processing rule: encoding mode solves content transmission, while filename cleaning solves display and disk storage, and the two things cannot be replaced by each other.

After modification, it is recommended to download the same Chinese attachment at least once using three types of clients, confirm that the name and suffix in the save dialog box are correct, and then check whether the two parameters in the response header exist at the same time.

Common questions

Question: Can it be convenient to just write filename*?Answer: The new client can display correctly, but the old client that does not support this parameter will revert to the default name. Therefore, the specification document suggests writing both together to ensure compatibility.

Question: Can the Chinese name be written directly in the parameter without a star?Answer: It is not recommended. Non-ASCII characters are easy to cause problems when header fields are transmitted literally, which is why parameters with stars exist. The fallback parameters should only contain ASCII approximate names.

Question: Should the file extension be standardized together?Answer: yes. Mixed case or missing suffixes will affect both download display and content type judgment, it is recommended to complete suffix whitelist verification at the upload stage, and only name restoration is done at the download stage.

Related functions

Preview

The interface documentation has been published, do we need to provide a site description for the model as well?

The interface documentation is aimed at the caller, explaining how to make requests and what public capabilities are available; the site description file is aimed at the large language model, helping the model understand and index the website content. Both have different readers and different functions, one manages calls and the other manages solutions, and both should be crawlable. The site description file is automatically generated by the system, working with the site map to divide labor: the site map manages discovery, and the description file manages solutions.

Preview

When managing multiple brand websites with the same system, how can the domain, language, and template be allocated separately?

When managing multi-brand, multi-theme websites with a single system, the site boundary determines the domain and backend entry, the language level determines the translation scope, and the content model determines whether fields are shared. The domain and main site language are independent of the site, the template and content model can be chosen between shared and independent, and navigation and single pages are maintained separately by the site.

Preview

The form on the station receives human verification, without popping up images, only deciding whether to check the checkbox based on risk, and the backend still needs to verify what

Human verification shifts from selecting images to risk-based clearance, Cloudflare Turnstile provides hosted, non-interactive, and invisible three forms, the checkbox only appears when the risk is high. The token handed over to the backend does not mean security, the server still needs to verify the source, grade the form scenario, and provide a return that can be processed in case of verification failure.