N/file Module: Manage Files in NetSuite SuiteScript
The N/file module enables file management in NetSuite SuiteScript, allowing uploads, attachments, and conflict resolution.
The N/file module is a powerful tool for developers working with files within NetSuite. It facilitates the uploading of files to the NetSuite File Cabinet, the ability to send files as attachments directly, and copying functionalities for existing files. Additionally, it provides options for conflict resolution, allowing users to manage scenarios where files with the same name may exist in the same folder.
Best Practices for File Naming
When uploading files using SuiteScript, adhere to best practices for file naming to avoid duplication. For systems managing multiple files, including timestamps with millisecond precision or a random number in the filename can help mitigate duplication issues.
Key Components of the N/file Module
The N/file module includes several key objects and methods:
File Object Members
| Member Type | Name | Return Type / Value Type | Supported Script Types | Description |
|---|---|---|---|---|
| Object | file.File | Object | Server scripts | Encapsulates a file within NetSuite. |
| Object | file.Reader | Object | Server scripts | Encapsulates a reader for special read operations. |
| Method | file.copy(options) | file.File | Server scripts | Copies an existing file in the File Cabinet. |
| Method | file.create(options) | file.File | Server scripts | Creates a new file. |
| Method | file.delete(options) | void | Server scripts | Deletes an existing file from the File Cabinet. |
| Method | file.load(options) | file.File | Server scripts | Loads an existing file from the File Cabinet. |
| Enum | file.Encoding | enum | Server scripts | Holds character encoding values. |
| Enum | file.NameConflictResolution | enum | Server scripts | Holds conflict resolution options for file copying. |
| Enum | file.Type | enum | Server scripts | Holds file type values. |
File Reader Object Members
| Member Type | Name | Return Type / Value Type | Supported Script Types | Description |
|---|---|---|---|---|
| Method | Reader.readChars(options) | string | Server scripts | Reads the next specified number of characters. |
| Method | Reader.readUntil(options) | string | Server scripts | Reads from current position until the delimiter. |
Important Notes on Performance
Methods that load content into memory, like File.getContents(), are limited to a maximum size of 10 MB. However, when using streaming methods—such as File.save()—this restriction does not apply. For operations involving large files, splitting them into smaller segments might enhance performance and reduce upload times.
When new or updated files are uploaded, they undergo screening for malicious content. Be mindful of increased file sizes, which could potentially slow upload processes.
Conclusion
The N/file module significantly enhances file handling in NetSuite by providing flexible methods for file management. Following best practices for file naming and being aware of size limitations will further optimize file operations.
Key Concepts:
- File Management: Enables uploading, attaching, and copying files.
- Conflict Resolution: Handling duplicate file scenarios intelligently.
- Performance Optimization: Best practices for file sizes and naming conventions.
Frequently Asked Questions (4)
What permissions are required to use the N/file module in NetSuite?
How does the N/file module handle conflicts with files having the same name during uploads?
Are there any specific recommendations for naming files when using SuiteScript to avoid duplication?
What is the file size limit for loading content into memory using the N/file 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.
- 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.
