0

I'm currently working on a small Spring-based web application with an AngularJS frontend. One can upload and download files to it, which are mirrored to some other storage. If I download a file, the application checks if all replicas are there and valid, and if not it re-uploads the file to the storage with a corrupted copy of the file.

The thing I want to achive is, that when I download the file, I want to be able to additionally transfer data about the replicas. More specifically, I want to state to the user, if the file was coruppted somewhere and had to be uploaded. And if so, where this happened.

The code I'm currently using is (I know that it's not very efficient to download from all providers everytime):

public ResponseEntity downloadFile(@RequestParam("fileName") String filename) {
    *) Download the file from each storage
    *) Check if all replicas are ok
    *) If not find the corrupted ones and reupload the file
    *) Get one of the OK copies and store it in byte array named "file"
    *) Create some headers and store them in a variable named "headers"
    return new ResponseEntity<>(file, headers, HttpStatus.OK);
}

What I want to know is:

Is it possible to return something that holds some additional information about the corrupted replicas and which is still handled by the browser like a normal file? So instead of returning a byte array, I would return some other magical object that holds the content of the file, with some additional data?

wastl
  • 2,643
  • 14
  • 27
  • You can return whatever you want. However, a browser has some conventions/standards that it follows. If what you return in your HTTP response doesn't follow those conventions/standards, you won't get what you want. – Sotirios Delimanolis Nov 03 '15 at 21:55
  • Ok. Do you maybe have any pointers on how to achive a download-dialog, while still being able to transmit additional data in one response? – wastl Nov 03 '15 at 22:02
  • Typically this additional info would be passed as response headers. The browser probably wouldn't interpret it, but your other clients (ajax, etc.) could. – Sotirios Delimanolis Nov 03 '15 at 22:02
  • Thank you for your comment, it finally brought me on the right path and led me to this http://stackoverflow.com/a/27442914/3669613 answer. – wastl Nov 03 '15 at 23:00

0 Answers0