File corrupted on download from S3 and angular

Viewed 23

I'm trying to download a S3 file from my java code and return it to my angular code. When I click to download it, it brings up the save dialog, but after it saves the file size changes and the contents are corrupted and can't be opened as a gif.

Before: giphy2.gif, 7805441 bytes
After: giphy2.gif, 11316215 bytes

Angular Code:

  /**
   * This will open a Save File dialog that will allow the user to download the file specified by the passed in URI
   */
  public download(uri: string)
  {
      window.location.href = Environment.hostUrl + 'proxy/stream/ds/download/?uri=' + encodeURIComponent(uri);
  }

Java Code:

    @GetMapping(value = "/download")
    @ResponseBody
    public Object download(
      @RequestParam String uri
    )
    {
       S3Object s3File = s3.getFile(util.extractBucketName(uri), util.extractObjectKey(uri));
       InputStreamResource resource = new InputStreamResource(s3.stream(s3File));

       return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM)
         .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\"")
         .body(resource);
    }

Does anyone know what is going on?

0 Answers
Related