0

I have a spring boot backend what serves me with files (in this case a jpeg file).

This is how the spring rest controller looks like:

    @Override
    public ResponseEntity<Resource> get(Long id) {
        MyCustomFile entity = service.get(id);

        if (entity == null) {
            return ResponseEntity.notFound().build();
        }

        return new ResponseEntity<>(toResource(entity), toHeaders(entity), HttpStatus.OK);
    }

    protected Resource toResource(MyCustomFile myfile) {
        return toResource(myfile.getContent()); 
              // here the getContent() returns array of bytes: private byte[] content;
    }

    protected Resource toResource(byte[] data) {
        return new ByteArrayResource(data);
    }

But how to consume this in my flutter app? At the moment I have this:

  getFileById(int id, String token) async {
    var response = await http.get(Uri.parse("$URL$id"), headers: {
      HttpHeaders.authorizationHeader: 'bearer $token',
    });
  }

I have the response object, but I don't know how to turn into a file so I can handle it... (save it to the phone for example...)

When I print the response.body:

enter image description here

stacktrace2234
  • 516
  • 4
  • 11

0 Answers0