binary

response.binary(body, mimeType)

Returns a successful binary response with optional MIME type.

Parameters:

The method has the following parameters:

ParameterDescription
bodyArray of bytes (represented by integer numbers in range 0-255).
mimeTypeOptional. Any binary MIME type, for example:
application/zip
application/pdf
* image/jpeg
Example

Returns a successful binary response.

try {
  // Binary data
  response.binary([80, 75, 5, 6, 0, 0]);
} catch (e) {
  // Redirect to error page
  response.redirect("http://error.page.com");
}
UEsFBgAA
Example

Returns a successful response with a binary data and MIME type.

var secureCode = request.get("secureCode");
 
if (validateCode(secureCode)) {
  try {
    // Send binary data
    response.binary([80, 75, 5, 6, 0, 0], "application/zip");
  } catch (e) {
     // Redirect to error page
    response.redirect("http://error.page.com");
  }
} else {
   // Respond with error message and code
  response.error("Secure code is not valid", "Unauthorized"); //It's possible to use error code instead of its name
  //response.error("Cannot find an article", 401) //Works the same
}
Error code SCSE014: Script execution failed. Details have been added to Trace tab.