file.create(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Method used to create a new file in the NetSuite File Cabinet.

Important:

Content held in memory is limited to 10MB.

Returns

file.File

Supported Script Types

Server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

None

Module

N/file Module

Since

2015.2

Parameters
Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

Since

options.name

string

required

  • The file name and extension.

  • Sets the value for the File.name property.

2015.2

options.fileType

enum

required

  • The file type.

  • Sets the value for the File.fileType property. This property is read-only and cannot be changed after the file is created.

  • Use the file.Type enum to set the value.

2015.2

options.contents

string

optional

  • The file content.

  • File content is lazy loaded; there is no property for it.

  • If the file type is binary (for example, PDF), the file content must be base64 encoded.

2015.2

options.description

string

optional

  • The file description. In the UI, the value of description displays the Description field on the file record.

  • Sets the value for the File.description property.

2016.2

options.folder

number

optional

  • The internal ID of the folder within the NetSuite File Cabinet. You must set the File Cabinet folder before you upload a file to the NetSuite File Cabinet with File.save().

  • Sets the value for the File.folder property.

2016.1

options.encoding

string

optional

  • The character encoding on a file.

  • Sets the value for the File.encoding property.

  • Use the file.Encoding enum to set the value. For more information about converting strings to another type of encoding, see N/encode Module.

2016.2

options.isInactive

boolean

optional

  • The inactive status of a file. If set to true, the file is inactive. The default value is false. When a file is inactive, it does not display in the UI unless you select Show Inactives on the File Cabinet page.

  • Sets the value for the File.isInactive property.

2016.2

options.isOnline

boolean

optional

  • The Available without Login status of a file. If set to true, users can download the file outside of a current netSuite login session. The default value is false.

  • Sets the value for the File.isOnline property.

2016.2

Errors

Error Code

Message

Thrown If

SSS_MISSING_REQD_ARGUMENT

<name of missing parameter>

A required argument is not passed.

SSS_INVALID_TYPE_ARG

You have entered an invalid type argument: <passed type argument>

The argument for File.fileType is invalid.

SSS_FILE_CONTENT_SIZE_EXCEEDED

The file you are trying to create exceeds the maximum allowed file size of 10.0 MB.

You attempt to create a file larger than 10MB.

Syntax
Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/file Module Script Samples.

          //Add additional code 
...
var fileObj = file.create({
    name: 'test.txt',
    fileType: file.Type.PLAINTEXT,
    contents: 'Hello World\nHello World',
    description: 'This is a plain text file.',
    encoding: file.Encoding.UTF8,
    folder: 30,
    isOnline: true
});
...
 //Add additional code 

        

Related Topics

N/file Module
N/encode Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices