Sending Files
We all need to deliver files to users at one point in time. ColdBox makes it easy to deliver any type of file even binary files via the Request Context's (event) sendFile() method.
1
function report( event, rc, prc ){
2
var prc.reportFile = reportService.createReport();
3
4
event
5
.sendFile(
6
file = prc.reportFile,
7
name = "UserReport.xls",
8
deleteFile = true
9
)
10
.noRender();
11
}
Copied!

Method Signature

The method signature is as follows:
1
/**
2
* This method will send a file to the browser or requested HTTP protocol according to arguments.
3
* CF11+ Compatibility
4
*
5
* @file The absolute path to the file or a binary file to send
6
* @name The name to send to the browser via content disposition header. If not provided then the name of the file or a UUID for a binary file will be used
7
* @mimeType A valid mime type to use. If not passed, then we will try to use one according to file type
8
* @disposition The browser content disposition (attachment/inline) header
9
* @abortAtEnd If true, then this method will do a hard abort, we do not recommend this, prefer the event.noRender() for a graceful abort.
10
* @extension Only used for binary files which types are not determined.
11
* @deleteFile Delete the file after it has been streamed to the user. Only used if file is not binary.
12
*/
13
function sendFile(
14
file="",
15
name="",
16
mimeType="",
17
disposition="attachment",
18
boolean abortAtEnd="false",
19
extension="",
20
boolean deleteFile=false
21
)
Copied!
Please note that the file argument can be an absolute path or an actual binary file to stream out.
Last modified 3yr ago
Copy link