How to download a file using a Java REST service and a data stream

后端 未结 3 1964
傲寒
傲寒 2020-12-13 05:08

I have 3 machines:

  1. server where the file is located
  2. server where REST service is running ( Jersey)
  3. client(browser) with
3条回答
  •  庸人自扰
    2020-12-13 05:35

    See example here: Input and Output binary streams using JERSEY?

    Pseudo code would be something like this (there are a few other similar options in above mentioned post):

    @Path("file/")
    @GET
    @Produces({"application/pdf"})
    public StreamingOutput getFileContent() throws Exception {
         public void write(OutputStream output) throws IOException, WebApplicationException {
            try {
              //
              // 1. Get Stream to file from first server
              //
              while() {
                  output.write()
              }
            } catch (Exception e) {
                throw new WebApplicationException(e);
            } finally {
                  // close input stream
            }
        }
    }
    

提交回复
热议问题