Server Response Write File Method in SuiteScript
The writeFile method allows SuiteScript to send files as HTTP responses. Learn about its parameters and error handling.
The writeFile method in SuiteScript serves a crucial role in HTTP responses by enabling scripts to write files back to the client. This method is especially useful for server scripts that need to deliver file content directly to users.
Method Description
The writeFile method is part of the http.ServerResponse object and is responsible for writing a file to the response stream. This function ensures that the file is appropriately handled and delivered to the requesting client.
Returns
- Type:
void
Supported Script Types
- Server scripts are the only types that support this method. For further details, refer to the SuiteScript 2.x Script Types.
Governance
- This method does not have any specific governance limitations.
Module
- The method belongs to the N/http Module.
Parameters
The options parameter, a JavaScript object, is essential for the writeFile method's functionality. Here are its components:
| Parameter | Type | Required / Optional | Description |
|---|---|---|---|
options.file | file.File | Required | A file.File object that represents the file to be written. |
options.isInline | boolean | Optional | When set to true, the file is treated as inline content. The default is false. |
Error Handling
The following errors may be thrown when using the writeFile method:
| Error Code | Message | Thrown If |
|---|---|---|
SSS_MISSING_REQD_ARGUMENT | Missing a required argument: {param name} | The options.file parameter is not supplied. |
WRONG_PARAMETER_TYPE | {param name} | The provided value for options.file is not a valid file.File object. |
Syntax
The code example below demonstrates the syntax for using the writeFile method:
1// Assume myFileObj is an instance of a file.File object2deliverFile(serverResponse) {3 serverResponse.writeFile({4 file: myFileObj,5 isInline: true6 });7}Related Topics
For more details about related topics, explore:
- http.ServerResponse
- N/http Module
- SuiteScript 2.x Modules
This method is vital for developers working with server-side scripts in SuiteScript, providing a seamless way to manage file responses.
Key Takeaways
- The
writeFilemethod allows writing files to HTTP responses in SuiteScript. - It requires the
options.fileparameter to be provided. - Error handling is essential to ensure the correct file type and presence of required parameters.
Frequently Asked Questions (4)
Does the writeFile method require any specific permissions or governance limitations?
Can the writeFile method be used in client scripts?
What parameter is essential for the writeFile method to function correctly?
What happens if the options.file parameter is not a valid file.File object?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
