Package com.axelor.rpc
Class ResponseFile
java.lang.Object
com.axelor.rpc.ResponseFile
A file sent to the client, set with
ActionResponse.setFile(ResponseFile).
The file content is copied to a pending export file, which the client downloads by token with
the ws/files/data-export endpoint. A token is only valid for the user who created it.
response.setFile(ResponseFile.preview(path, "invoice.pdf").title("Invoice"));
response.setFile(ResponseFile.download(stream, "export.zip"));
-
Method Summary
Modifier and TypeMethodDescriptionstatic ResponseFiledownload(InputStream stream) Create a file the client downloads.static ResponseFiledownload(InputStream stream, String fileName) Create a file the client downloads.static ResponseFileCreate a file the client downloads.static ResponseFileCreate a file the client downloads.export()Copy the file to a new pending export file, and describe it for the client.Get the name of the file.getTitle()Get the title of the tab the file is previewed in.booleanWhether the file was created to be downloaded, instead of previewed.static ResponseFilepreview(InputStream stream, String fileName) Create a file the client opens in a new tab for preview if supported by the browser; otherwise, it downloads it.static ResponseFileCreate a file the client opens in a new tab for preview if supported by the browser; otherwise, it downloads it.static ResponseFileCreate a file the client opens in a new tab for preview if supported by the browser; otherwise, it downloads it.Set the title of the tab the file is previewed in.
-
Method Details
-
preview
Create a file the client opens in a new tab for preview if supported by the browser; otherwise, it downloads it.- Parameters:
path- the path to the file, absolute or relative to the temporary directory- Returns:
- the file to preview, named after the given path
-
preview
Create a file the client opens in a new tab for preview if supported by the browser; otherwise, it downloads it.- Parameters:
path- the path to the file, absolute or relative to the temporary directoryfileName- the name of the file, defaults to the name of the path- Returns:
- the file to preview
-
preview
Create a file the client opens in a new tab for preview if supported by the browser; otherwise, it downloads it.- Parameters:
stream- the stream to the filefileName- the name of the file, whose extension tells whether it can be previewed- Returns:
- the file to preview
- Throws:
IllegalArgumentException- if the file name is blank
-
download
Create a file the client downloads.- Parameters:
path- the path to the file, absolute or relative to the temporary directory- Returns:
- the file to download, named after the given path
-
download
Create a file the client downloads.- Parameters:
path- the path to the file, absolute or relative to the temporary directoryfileName- the name of the downloaded file, defaults to the name of the path- Returns:
- the file to download
-
download
Create a file the client downloads.- Parameters:
stream- the stream to the file- Returns:
- the file to download, named after its pending export file
-
download
Create a file the client downloads.- Parameters:
stream- the stream to the filefileName- the name of the downloaded file- Returns:
- the file to download
-
title
Set the title of the tab the file is previewed in.It is ignored if the file is downloaded.
- Parameters:
title- the title of the tab, defaults to the file name- Returns:
- this file
-
getFileName
Get the name of the file.- Returns:
- the name of the file, or
nullif a stream was given without a name
-
getTitle
Get the title of the tab the file is previewed in.- Returns:
- the title of the tab, or
nullto use the file name
-
isDownload
public boolean isDownload()Whether the file was created to be downloaded, instead of previewed.A file created for preview is still downloaded if the browser cannot preview it.
- Returns:
trueif the file was created withdownload
-
export
Copy the file to a new pending export file, and describe it for the client.Each call creates a new pending export file with its own token, and reads the given stream to its end.
- Returns:
- the file token, name and format, as the client reads them
- Throws:
IllegalArgumentException- if a relative path resolves outside the temporary directoryUncheckedIOException- if the file cannot be read
-