Javascript 具有多个文件的JAXRS响应

Javascript 具有多个文件的JAXRS响应,javascript,java,reactjs,rest,jersey-2.0,Javascript,Java,Reactjs,Rest,Jersey 2.0,我能够向ReactJS发送单个图像文件。但我必须向ReactJS发送多个图像文件 JAXRS代码: @GET @Path("/download/file1") @Produces( MediaType.APPLICATION_OCTET_STREAM ) public Response getFile() { String fileName = DOWNLOAD_FILE_SERVER+"BMI/testcases/B

我能够向ReactJS发送单个图像文件。但我必须向ReactJS发送多个图像文件

JAXRS代码:

    @GET
    @Path("/download/file1")
    @Produces( MediaType.APPLICATION_OCTET_STREAM )
    public Response getFile() {
        String fileName = DOWNLOAD_FILE_SERVER+"BMI/testcases/Basispath_BMI_0_out.gif";
        File file = new File( fileName);
        System.out.println("fileName inside getFile = "+fileName);
        final String filename = "testcase1.gif"; 
        System.out.println("filename inside getFile = "+filename);

        // Create the JAXRS response
        // Don't forget to include the filename in 2 HTTP headers: 
        //
        // a) The standard 'Content-Disposition' one, and
        // b) The custom 'X-Suggested-Filename'  

        final Response.ResponseBuilder builder = Response.ok(
                file, MediaType.APPLICATION_OCTET_STREAM)
                .header("X-Actual-Content-Length", file.length())
                .header("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"");
       
        // All Done.
        return builder.build();
    }
代码:

downloadImage = () => {  
        axios({
            url: 'http://localhost:9900/EXAMPLE/rest/myresource/download/file1',
            method: 'GET',
            responseType: 'blob',             
          }).then((response) => {
              const url = window.URL.createObjectURL(new Blob([response.data]));
              const link = document.createElement('a');
              link.href = url;             
              var filename = 'Image1.gif'              
              link.setAttribute('download', filename);
              document.body.appendChild(link);
              link.click();
              document.body.removeChild(link);              
          })
          .catch((response) => { // then print response status
            console.log("response = ",response);            
        })
      }
问题:

  • 是否可以在JAXRS的响应中发送多个图像文件
  • 如何在ReactJS GET response中接收多个文件
  • 如何在ReactJS中显示收到的文件
  • 请提供此问题的解决方案

  • 也许只需对图像进行Base64编码并将其作为JSON字符串发送即可。你可以在客户端解码。谢谢你的回复。有没有示例代码?