BinaryData interface
A JavaScript object implementing the BinaryData
interface represents binary data, for example, a file which has just been uploaded in an HTTP request.
BinaryData
objects can be stored in the file store using O.file()
, and returned as HTTP responses by assigning them to E.response.body
.
Construction
Declare an as:"file"
argument on a request handler.
Load a file from your plugin’s file
directory with P.loadFile()
.
Construct binary data with O.binaryData()
.
Create an output file with a generator.
Interface
property digest
The digest of the file, as a hex encoded String
.
This property is read only.
property fileSize
The size of the file, in bytes, as a number.
This property is read only.
property mimeType
The MIME type of the file. Note that some MIME types are standardised as browsers tend to be a bit inconsistent.
This property can be changed.
property filename
The filename of the file, as set by the browser.
This property can be changed, which may be necessary before calling O.file()
to add it to the file store to make sure it has a sensible name. This is particularly useful when working with responses from the HTTP Client.
function readAsString(charsetName)
Return the contents of the binary data, interpreted as a string in the given character set, eg "UTF-8"
.
Use this function with care, checking the fileSize
property before calling it, as it is very easy to accidentally run out of memory.
function readAsJSON()
Parse the contents of the binary data as JSON, returning the JavaScript data structure. The data must be a valid UTF-8 string.