Home > Back-end >  Webservice generates a PDF, returned to the client file address, could you tell me how to write the
Webservice generates a PDF, returned to the client file address, could you tell me how to write the

Time:09-28

Webservice generates a PDF, my side is generated after the file address me the address of this site in the file, the client can't get the address to download the PDF only;
I this how to write client to download the address?

CodePudding user response:

One way to write
 private void downloadFile (HttpServletResponse response, the File File) {
/* set file ContentType type, such Settings, automatically download file types */
The response. SetContentType (" multipart/form - data ");
/* set file header: the last parameter is set to download the file name */
response.setHeader("Content-Disposition", "attachment; Filename="+ file. The getName ());
Try (
InputStream ins=new FileInputStream (file);
OutputStream OS=response. GetOutputStream ()
) {
Byte [] b=new byte [1024].
int len;
While ((len=ins. Read (b)) & gt; 0 {
OS. Write (b, 0, len);
}
} the catch (IOException ioe) {
Ioe. PrintStackTrace ();
}
}


This is ok

CodePudding user response:

No, I this way the client can only accept a url to download the PDF, others write good call, is there any way to my files are generated to his project, or the path of the PDF on my side can let him directly download?

CodePudding user response:

refer to the second floor answerdy response:
no, I this way the client can only accept a url to download the PDF, others write good call, is there any way to put my files are generated to his project, or the path of the PDF on my side can let him directly download?
there is no way to put your files are generated to his project, or asked him to write do you have the address that the File download method File=new File (path) it's not just finished? I didn't know what you're here to get you what is the meaning of a url?

CodePudding user response:

Webservice interface what form it is better to let the client to download files?
  • Related