具有多个文件的JAXRS响应

问题描述

我能够将单个图像文件发送到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();
    }

ReactJS代码

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);            
        })
      }

问题:

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)