ServerResponse Write File Functionality in SuiteScript
The ServerResponse module in SuiteScript provides a method for writing files to HTTP responses, essential for server-side file handling.
TL;DR
The ServerResponse module's writeFile method allows SuiteScript developers to write files directly to HTTP responses, which is crucial for server-side applications. This method enhances how files are managed and served to clients in NetSuite environments.
Overview of the writeFile Method
The writeFile method is part of the http.ServerResponse object in SuiteScript. This functionality is useful when you want to send files from the server to the client's browser efficiently.
Method Description
- Functionality: Writes a file to the HTTP response.
- Returns: This method does not return a value (i.e.,
void).
Supported Script Types
The writeFile method can be utilized in server scripts. For further reference on script types, consult the SuiteScript 2.x Script Types.
Governance
- Governance: This method has no governance limits, allowing developers to use it without restrictions on usage.
Parameters
The writeFile method accepts an options parameter, which is a JavaScript object. Here’s a closer look at the parameters you can pass:
| Parameter | Type | Required / Optional | Description |
|---|---|---|---|
options.file | file.File | Required | A file.File object that encapsulates the file to be written. |
options.isInline | boolean | Optional | If true, the file is sent as inline; defaults to false. |
Note: The file parameter is mandatory, and omitting it will trigger an error.
Error Handling
When utilizing writeFile, be aware of the following potential errors:
- Error Code:
SSS_MISSING_REQD_ARGUMENT- Message: Missing a required argument: {param name}
- Thrown If: The
options.fileparameter is not specified.
- Error Code:
WRONG_PARAMETER_TYPE- Message: {param name}
- Thrown If: The value provided for
options.fileis not a validfile.Fileobject.
Example of Using writeFile
Here’s a syntax example demonstrating how to implement the writeFile method:
1// Add additional code 2...3serverResponse.writeFile({4 file: myFileObj,5 isInline: true6});7...8// Add additional codeThis example illustrates how to write a file named myFileObj as an inline file in the server response.
Related Topics
For further reading, you might find these topics useful:
- http.ServerResponse
- N/http Module
- SuiteScript 2.x Modules
Key Takeaways
- The
writeFilemethod is essential for sending files in HTTP responses. - Omitting required parameters will result in errors.
- Inline file transfer can enhance user experience in web applications.
Frequently Asked Questions (4)
What script types support the use of the ServerResponse writeFile method?
Are there any governance limits when using the writeFile method in SuiteScript?
What happens if the 'options.file' parameter is not specified when using writeFile?
Can the file provided to writeFile be sent as inline, and how is this configured?
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.
