How to make the browser download pictures directly returned by the backend instead of opening

By default, the browser settings are inline form for the file server returned to open to open, not open automatically download.

In most cases, the back end is the realization of a file management function, to get the file stream through the only sign documents. Backend reads the file and then written to the response stream output stream file, so that you can achieve the access to the file.

But sometimes, to achieve download functions, the picture is returned by the backend, but directly to the picture browser to open up? what happened?

That is the problem Content-Disposition set, the following are examples of java:

Is set to inline, if the browser supports the file type preview will open, instead of downloading:

response.setHeader("Content-Disposition", "inline; filename=111.jpg");
Set attachment, download the browser directly, even if he was able to preview the type of file.

response.setHeader("Content-Disposition", "attachment; filename=111.jpg");
Special Note: Chrome is not set Content-Type will open automatically, if it can be identified preview files.

Published 552 original articles · won praise 201 · views 180 000 +

Guess you like

Origin blog.csdn.net/sinat_42483341/article/details/104045664