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

file.File

Object

Server scripts

Encapsulates a file within NetSuite.

file.Reader

Object

Server scripts

Encapsulates a reader that you can use to perform special read operations.

Method

file.copy(options)

file.File

Server scripts

Copies an existing file in the File Cabinet.

file.create(options)

file.File

Server scripts

Creates a new file.File.

file.delete(options)

void

Server scripts

Deletes an existing file.File from the NetSuite File Cabinet.

file.load(options)

file.File

Server scripts

Loads an existing file.File from the NetSuite File Cabinet.

Enum

file.Encoding

enum

Server scripts

Holds character encoding values for file contents.

This enum is used to set the value of the File.encoding property.

file.NameConflictResolution

enum

Server scripts

Holds conflict resolution values that apply when copying a file.

file.Type

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

File.appendLine(options)

file.File

Server scripts

Inserts a line to the end of a CSV or text file.

File.getContents()

string

Server scripts

Returns the content of a file in string format.

File.lines.iterator()

boolean

Server scripts

Calls a developer-defined function for each line. Returns false when line processing stops.

File.resetStream()

void

Server scripts

Resets the file stream to its previous state.

File.save()

number

Server scripts

Saves a new or updated file to the File Cabinet.

File.getReader()

Object

Server scripts

Returns reader object for read operations.

File.getSegments(options)

Object

Server scripts

Returns an iterator of segments that are delimited by the specified separator.

Property

File.description

string

Server scripts

Description of a file.

File.encoding

string

Server scripts

Character encoding on a file.

File.fileType

enum

Server scripts

File type of a file.

File.folder

number

Server scripts

Internal ID of the folder that houses a file within the NetSuite File Cabinet.

File.id

number (read-only)

Server scripts

Internal ID of a file in the NetSuite File Cabinet.

File.isInactive

boolean

Server scripts

Inactive status of a file. If set to true, the file is inactive.

File.isOnline

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.

File.isText

boolean (read-only)

Server scripts

Indicates whether a file type is text-based.

File.name

string

Server scripts

Name of a file.

File.path

string (read-only)

Server scripts

Relative path to a file in the NetSuite File Cabinet.

File.size

number (read-only)

Server scripts

Size of a file in bytes.

File.url

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

Reader.readChars(options)

string

Server scripts

Returns the next options.number characters from the current position.

Reader.readUntil(options)

string

Server scripts

Returns string from current position to the next occurrence of options.tag.

Related Topics

General Notices