N/file Module: Manage Files in NetSuite SuiteScript

The N/file module enables file management in NetSuite SuiteScript, allowing uploads, attachments, and conflict resolution.

·3 min read·View Oracle Docs

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 TypeNameReturn Type / Value TypeSupported Script TypesDescription
Objectfile.FileObjectServer scriptsEncapsulates a file within NetSuite.
Objectfile.ReaderObjectServer scriptsEncapsulates a reader for special read operations.
Methodfile.copy(options)file.FileServer scriptsCopies an existing file in the File Cabinet.
Methodfile.create(options)file.FileServer scriptsCreates a new file.
Methodfile.delete(options)voidServer scriptsDeletes an existing file from the File Cabinet.
Methodfile.load(options)file.FileServer scriptsLoads an existing file from the File Cabinet.
Enumfile.EncodingenumServer scriptsHolds character encoding values.
Enumfile.NameConflictResolutionenumServer scriptsHolds conflict resolution options for file copying.
Enumfile.TypeenumServer scriptsHolds file type values.

File Reader Object Members

Member TypeNameReturn Type / Value TypeSupported Script TypesDescription
MethodReader.readChars(options)stringServer scriptsReads the next specified number of characters.
MethodReader.readUntil(options)stringServer scriptsReads 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.

Source: This article is based on Oracle's official NetSuite documentation.

Frequently Asked Questions (4)

What permissions are required to use the N/file module in NetSuite?
The article does not specify the exact permissions needed to use the N/file module. Generally, managing files in NetSuite will require roles with access to the File Cabinet and appropriate SuiteScript deployment permissions.
How does the N/file module handle conflicts with files having the same name during uploads?
The N/file module uses the Enum 'file.NameConflictResolution' to handle file name conflicts, allowing developers to resolve scenarios where files with the same name may exist in the same folder.
Are there any specific recommendations for naming files when using SuiteScript to avoid duplication?
Yes, it's recommended to include timestamps with millisecond precision or a random number in the filename, especially in systems managing multiple files, to mitigate duplication issues.
What is the file size limit for loading content into memory using the N/file module?
Methods that load content into memory, such as File.getContents(), are limited to a maximum file size of 10 MB. Streaming methods, like File.save(), do not have this restriction.
Source: N/file Module Members Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Platform

View all Platform articles →