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
@Get
public SystemFile download() {
File file = ...
return new SystemFile(file).attach("myfile.txt");
// or new SystemFile(file, MediaType.TEXT_HTML_TYPE)
}