N/file Module
Use the N/file module to work with files within NetSuite. You can use this module to upload files to the NetSuite File Cabinet, as well as send files as attachments without uploading them to the File Cabinet. You can also use this module to copy files in the File Cabinet, and you can use conflict resolution options to handle conflicts (such as when a file with the same name already exists in the same folder in the File Cabinet).
A file.Reader object, which is returned by File.getReader(), can be used for special read operations. Use File.getSegments(options) to retrieve an iterator of custom segments of a file.
Methods that load content in memory, such as File.getContents(), have a 10 MB size limit. This limit does not apply when content is streamed, such as when File.save() is called.
The File.appendLine(options) method inserts a line to the end of a CSV or text file, which increases the file size accordingly. All files are screened for malicious content when they are uploaded or updated, and increased file size can slow down the process. Consider splitting large files into several smaller ones if you experience performance issues.
In This Help Topic
N/file Module Members
Member Type |
Name |
Return Type / Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Object |
Object |
Server scripts |
Encapsulates a file within NetSuite. |
|
Object |
Server scripts |
Encapsulates a reader that you can use to perform special read operations. |
||
Method |
Server scripts |
Copies an existing file in the File Cabinet. |
||
Server scripts |
Creates a new file.File. |
|||
void |
Server scripts |
Deletes an existing file.File from the NetSuite File Cabinet. |
||
Server scripts |
Loads an existing file.File from the NetSuite File Cabinet. |
|||
Enum |
enum |
Server scripts |
Holds character encoding values for file contents. This enum is used to set the value of the File.encoding property. |
|
enum |
Server scripts |
Holds conflict resolution values that apply when copying a file. |
||
enum |
Server scripts |
Holds file type values. This enum is used to set the value of the File.fileType property. |
File Object Members
The following members are available for a file.File object.
Member Type |
Name |
Return Type / Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Method |
Server scripts |
Inserts a line to the end of a CSV or text file. |
||
string |
Server scripts |
Returns the content of a file in string format. |
||
boolean |
Server scripts |
Calls a developer-defined function for each line. Returns false when line processing stops. |
||
void |
Server scripts |
Resets the file stream to its previous state. |
||
number |
Server scripts |
Saves a new or updated file to the File Cabinet. |
||
Object |
Server scripts |
Returns reader object for read operations. |
||
Object |
Server scripts |
Returns an iterator of segments that are delimited by the specified separator. |
||
Property |
string |
Server scripts |
Description of a file. |
|
string |
Server scripts |
Character encoding on a file. |
||
enum |
Server scripts |
File type of a file. |
||
number |
Server scripts |
Internal ID of the folder that houses a file within the NetSuite File Cabinet. |
||
number (read-only) |
Server scripts |
Internal ID of a file in the NetSuite File Cabinet. |
||
boolean |
Server scripts |
Inactive status of a file. If set to true, the file is inactive. |
||
boolean |
Server scripts |
“Available without Login” status of a file. If set to true, users can download the file outside of a current NetSuite login session. |
||
boolean (read-only) |
Server scripts |
Indicates whether a file type is text-based. |
||
string |
Server scripts |
Name of a file. |
||
string (read-only) |
Server scripts |
Relative path to a file in the NetSuite File Cabinet. |
||
number (read-only) |
Server scripts |
Size of a file in bytes. |
||
string (read-only) |
Server scripts |
URL of a file. |
Reader Object Members
The following members are available for a file.Reader object.
Member Type |
Name |
Return Type / Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Method |
string |
Server scripts |
Returns the next |
|
string |
Server scripts |
Returns string from current position to the next occurrence of |