2

This has tons of example on the internet but for some reason I just cannot download a csv file. I keep getting the error:

org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation`. 

Here is the code below for my @RestController:

      @GetMapping(value = "/tasks/{taskId}/download", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
      public ResponseEntity<InputStreamResource> download(@PathVariable String taskId, @RequestParam String format) throws IOException {

        var path = "string path to file"

        var file = new UrlResource(Path.of(path).normalize().toUri());
        return ResponseEntity
            .ok()
            .contentLength(file.contentLength())
            .contentType(
                MediaType.parseMediaType("application/octet-stream"))
            .body(new InputStreamResource(file.getInputStream()));
      }

I set the header Accept: application/octet-stream but still get the same error. What could be wrong any ideas?

Cemre Mengü
  • 18,062
  • 27
  • 111
  • 169

0 Answers0