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
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:
1"text-purple-400">require(['N/https'], "text-purple-400">function(https) {2 "text-purple-400">var fileData = '...'; // Base64 encoded data of your file3 "text-purple-400">var binaryData = Uint8Array.fromBase64(fileData);4 5 "text-purple-400">var options = {6 url: 'https://example.com/upload',7 body: binaryData8 };9 10 "text-purple-400">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.
Source: This article is based on Oracle's official NetSuite documentation.
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
- N/https Module: Binary File Support in NetSuite 2025.2
NetSuite 2026.1 adds binary file support to N/https for streamlined file handling.
- Attach and Detach Operations in NetSuite 2026.1
Attach and detach operations for record relationships in NetSuite enhance data management and connectivity.
- Create-Form Operation in NetSuite 2026.1 REST Web Services
Create-form operation in NetSuite 2026.1 APIs streamlines record creation and enhances efficiency.
- Improved Execution Log Support in NetSuite 2026.1
Improved execution log support in NetSuite 2026.1 aids debugging and performance tracking for developers.