One, not the same host, through the way to the other file
Controller
@RequestMapping (value = "/down/{uuid}", method = Requestmethod.get) @ResponseBody public void Downloadimage (@PathVariab Le ("uuid") final String uuid, httpservletresponse response) {flservice.downimage (UUID, response); }
Service
void Downimage (String uuid, httpservletresponse response);
Serviceimpl
@Overridepublic void Downimage (String uuid, httpservletresponse response) {//response.setheader ("content-disposition "," attachment;filename= "+" asdf.jpg "); Download Response.setcontenttype ("Image/png");//display string Realpath = "C:\\users\\public\\pictures\\sample Pictures\\ Asdf.jpg "; InputStream fileinputstream;try {fileinputstream = new FileInputStream (realpath); OutputStream OutputStream = Response.getoutputstream (); Ioutils.copy (FileInputStream, OutputStream); Outputstream.close (); Fileinputstream.close ();} catch (Exception e) {e.printstacktrace ();}}
Implementing File Downloads
Response.setheader ("Content-disposition", "attachment;filename=" + "asdf.jpg");
Implementation files are displayed in the browser
Response.setcontenttype ("Image/png");
Second, if the same host, you can give the URL to each other, through the Nginx proxy way access.
SPRINGMVC implement picture download and display in browser