I have a byte array as data. Now how do I write a controller method to return this byte array as file using Spring Boot? If I create a file out of this byte array data, then I should also take care of deleting it right?
Is there a way to send this byte array as file without having to physically create a file in my project, maybe send all bytes through the network or something?
However if that's not possible, is file creation, responding in rest api and then deleting it is the only way to solve this? My controller method would look like this in spring boot
@GetMapping("/download")
public ResponseEntity<Resource> download(String param) throws IOException {
// Assume I already have this byte array from db or something
Byte[] a = getItFromDB();
// return it as a file without explicitly creating another file in my machine
// I am ok with changing return type of this method from ResponseEntity to anything else if you have a solution
}