Sending File Objects

It is possible to simply return a File object from your controller method and the data will be returned to the client. The Content-Type header of file responses will be calculated based on the name of the file.

To control either the media type of the file being sent, or to set the file to be downloaded (i.e. using the Content-Disposition header) you should instead construct an SystemFile with the file object you would like to be used. For example:

Sending a SystemFile

  1. @Get
  2. public SystemFile download() {
  3. File file = ...
  4. return new SystemFile(file).attach("myfile.txt");
  5. // or new SystemFile(file, MediaType.TEXT_HTML_TYPE)
  6. }