Sending File Objects

It is possible to return a File object from your controller method, and the data will be returned to the client. The Content-Type header of file responses is 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), instead construct a SystemFile with the file to use. 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. }