title: How to send a ByteArrayResource via ResponseEntity
body: <p>I am working on a Java application, and the functionality I am working on is to download a file after populating it's content from the database when the user clicks on export button, the file is generated correctly, the problem I have is when I try to set <strong>ByteArrayResource</strong> into the <strong>ResponseEntity</strong>, when I call the webservice from angular, I get <strong>Byte array resource [resource loaded from byte array] cannot be resolved to absolute file path</strong>, here is my code :</p>
  <p>Controller method :</p>
  <pre><code>  @GetMapping(value = &quot;/exportods/{id}&quot;)
    public ResponseEntity&lt;ExportDTO&gt; exportODSFile(@PathVariable  String id)
        throws InvalidationRequestNotFoundException, IOException, ExportInvalidationRequestException {
  
  
      File odsFfile = null;
      ByteArrayResource resource = null;
      ExportInvalidationRequestDTO exportInvalidationRequestDTO = new ExportInvalidationRequestDTO();
      try {
  
        //getting the file
        odsFfile = exportService.exportInvalidationRequest(id);
  
        Path pathObj = Paths.get(odsFfile.getCanonicalPath());
  
        //creating the resource
        resource = new ByteArrayResource(Files.readAllBytes(pathObj));
  
        exportDTO.setResource(resource);
  
      } catch (IOException e) {
        exportDTO.setError(new ErrorDTO(HttpStatus.NOT_FOUND.value()));
      }
  
      return ResponseEntity.ok(exportDTO);
    }
  </code></pre>
  <p>ExportDTO :</p>
  <pre><code>public class ExportDTO extends AbstractReturnDTO {
    private ByteArrayResource resource;
  
    public ExportDTO (ByteArrayResource resource) {
      this.resource = resource;
    }
  
    public ExportDTO () {
    }
  
    public ByteArrayResource getResource() {
      return resource;
    }
  
    public void setResource(ByteArrayResource resource) {
      this.resource = resource;
    }
  }
  </code></pre>
  <p>Angular component method:</p>
  <pre><code>async downloadODSFile(id) {
      await this.requestService.downloadODSFile(id).subscribe((requestExportODS: RequestExportODS) =&gt; {
          if (!requestExportODS) {
              if(requestExportODS.error == null){
                  //handle error here
              }
             else{
                  saveAs(new Blob([requestExportODS.file], { type: \'application/vnd.oasis.opendocument.spreadsheet\'' }), id );
              }
          }
      });
  }
  </code></pre>
  <p>Once I click on the export button, I get an error :</p>
  <pre><code>error: &quot;Internal Server Error&quot;
  message: &quot;Byte array resource [resource loaded from byte array] cannot be resolved to absolute file path&quot;
  </code></pre>