How to use Content-Disposition during file download

When doing web development, you may encounter the following requirements:
l Hope that a file of a certain type or a known MIME type (for example: *.gif;*.txt;*.htm) can pop up a "file" when accessing Download dialog box.
l It is hoped that the client will display it with the specified file name when downloading.
l Want a file to be displayed directly on the browser instead of popping up a file download dialog.
For the above requirements, using the Content-Disposition property can be solved. Here is the code example:
response.setHeader("Content-disposition", "attachment;filename=" + fileName).
//Content-disposition is the property name.
//attachment means downloading as an attachment. If you want to open in a page, change to inline.
//If the filename is Chinese, garbled characters will appear. There are two solutions:
//1. Use fileName = new String(fileName.getBytes(), "ISO8859-1") statement
//2. Use fileName = HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) Statement


reference : http://blog.163.com/liulei0729@126/blog/static/32530612201011122438316/

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326970252&siteId=291194637