Binary File Support in N/https Module for SuiteScript
Discover how to send binary files using the N/https module in SuiteScript, enhancing your integration capabilities. TL;DR Opening
TL;DR Opening
You can now send binary files in SuiteScript using the N/https module. By converting the file contents to a Uint8Array with Uint8Array.fromBase64(), you can include it in the options.body parameter for https.post(options) requests. Each request can handle only one file.
How Does Binary File Support Work?
Starting in NetSuite, the ability to send binary files via the N/https module significantly enhances the usage of web services in SuiteScript. The new approach involves converting file contents into a Uint8Array, which can then be sent as part of an HTTPS POST request. This opens up various possibilities for integrations involving file uploads, such as sending images, documents, or other file types programmatically.
How to Use N/https to Send a Binary File
Here’s a step-by-step guide on how to send a binary file in SuiteScript:
- Convert the File: Convert your file data to a Base64 string.
- Create a Uint8Array: Utilize
Uint8Array.fromBase64()to create aUint8Arrayfrom the Base64 encoded string. - Set Up Options: Prepare the options object which defines the HTTP request settings.
- Send the Request: Use
https.post(options)to send the request.
Example Code Snippet
Here is a code snippet demonstrating how to send a binary file:
1require(['N/https'], function(https) {2 var fileData = '...'; // Base64 encoded data of your file3 var binaryData = Uint8Array.fromBase64(fileData);4 5 var options = {6 url: 'https://example.com/upload',7 body: binaryData8 };9 10 var response = https.post(options);11 log.debug('Response', response);12});Important Considerations
When sending binary data:
- NetSuite automatically sets the
Content-Typetoapplication/octet-streamwhen usingUint8Array. You may modify this header to suit the file type if necessary. - It is not possible to send files with the
multipart/form-datacontent type. - Note that the
Uint8Arraybody feature is only supported in SuiteScript 2.1 and later.
Governing and Timeouts
It's crucial to be mindful of the following constraints while using the N/https module:
- A connection will time out if it takes longer than 5 seconds to establish.
- If the payload takes over 45 seconds to transmit, it will also time out.
- This method is not applicable in unauthenticated client-side contexts, limiting its use cases.
Who This Affects
- Developers: Implementing integrations that require uploading files.
- Administrators: Managing SuiteScript functionalities and deployment.
Key Takeaways
- Binary file support in the
N/httpsmodule enables sending files usingUint8Arrayin SuiteScript. - The
https.post(options)method is essential for initiating such requests. - Pay attention to timeout settings and the restrictions on
Content-Typeheaders.
Frequently Asked Questions (4)
Is binary file support in the N/https module available in all versions of SuiteScript?
What file types can be sent using the N/https module's binary file support?
Can I send multiple files in a single HTTPS POST request using the N/https module?
Do I need to configure additional headers when sending binary data with the N/https module?
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.
- 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.
- 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.
