Has anyone in the NS developer world ever push/upload a csv file from external drive into Netsuite file cabinet using a RESTlet

I implemented (tried to) the  file-cabinet-api restlet (Tim D) and testing with Postman. My Tokens are good as I tested with a GET call using a simple Hello World function. When I try to use the fileCreate function in the restlet to upload a file from my local drive to the file cabinet, it fails. I used the Hello World example in the script, but no file was created. I tried fileGet and it didn’t work either.
I have searched and searched and it seems that no one has done this using a NS RESTlet.  I have successfully implemented an email capture plug-in that pushed a csv file into the File Cabinet, but when you have financial data, email is unacceptable.
Thanks for any help.  Since I’m new, I will continue to search this community.
Rookie Asked on March 18, 2021 in SuiteScript.

If you can post sample code for your restlet, we can walk you through the suitescript to save the file to  the filecabinet.  You can also do this easily using suitetalk.

on March 21, 2021.

var file,log;

define( [ ‘N/file’, ‘N/log’], main );

function main( fileMod, logMod ) {

file = fileMod;
log = logMod;

return {
post: postProcess


function postProcess( request ) {

if ( ( typeof request.function == ‘undefined’ ) || ( request.function == ” ) ) {
return { ‘error’: ‘No function was specified.’ }

switch ( request.function ) {

case ‘fileCreate’:
return fileCreate( request )

var response = { ‘error’: ‘Unsupported Function’ }
return response;



function fileCreate( request ) {

// Load the file.

try {

var myfile = file.create(
name: request.name,
fileType: request.fileType,
contents: request.contents,
description: request.description,
encoding: request.encoding,
folder: request.folderID


// Save the file and get its ID.
var fileID = myfile.save();

// Load the file.
myfile = file.load( { id: fileID } );

// Create the response.
var response = {};
response[‘info’] = myfile;
response[‘content’] = myfile.getContents();

return response;

} catch (e) {
return { ‘error’: e }


on March 22, 2021.
Add Comment
4 Answer(s)

I’ve done it before (technically, worked with any file below about 9MB).  I don’t have the code with me though.  CSV shouldn’t be very hard.  Do the following:

  1.  Read the CSV file using a programming language of your choice.  It’s a text file, so you should be able to just read it.
  2. Use a POST request to send it to your Restlet
  3. On the restlet side, hook up to the POST event and receive the JSON/String.  (technically, you could use GET as well, but I prefer POST)
  4. Using the File API, write it to the file system.
  5. As said, you may have to watch it on size as scripts have a size limit in what they can handle with files.

I believe you can also directly post files to a restlet and the restlet will understand that and turn it into a nlobjFile object… though I’ll have to go back and check.

Anyways, keep trying at it, and try and follow the 5 steps listed above, and you should be alright.

Rookie Answered on March 19, 2021.

Thanks Michael. I’ll keep trying. My CSV’s are <1MB so I certainly don’t need to worry about the size of the file.

on March 19, 2021.
Add Comment

Keep in mind this to create the file correctly, you can use the file.Type Enum to set the type as a CSV.
To create a CSV file you have to use the encoding of UTF8, you also can use the file.Encoding Enum to get the correct encoding constant.

    name: request.fileType ,
    fileType: file.Type.CSV,
    encoding: file.Encoding.UTF8

Rookie Answered on March 29, 2021.
Add Comment

Use the below code, besides images it works well for csv, txt, log and PDF


* @NApiVersion 2.x
* @NScriptType Restlet
define([‘N/file’, ‘N/encode’, ‘N/log’], function (file, encode, log) {
functionpost(context) {
log.debug(‘Received context’, JSON.stringify(context));
try {
varextension=fileName.split(‘.’).pop().toUpperCase(); // Get the file extension
// Decode the base64 content for text-based files
if ([‘TXT’, ‘CSV’, ‘LOG’, ‘TEXT’].includes(extension)) {
varfileTypeMapping= {
varfileType=fileTypeMapping[extension] ||file.Type.PLAINTEXT; // Default to plain text if extension is not recognized
log.debug(‘Creating file’, { name:fileName, type:fileType });
log.debug(‘Saving file’);
log.audit(‘File uploaded successfully’, fileUrl);
return {
message:’File uploaded successfully!’,
} catch (e) {
log.error(‘Error in file upload’, e.toString());
return {
return {

Encode base64 at source

with open(file_name, “rb”) as f:
base64_bytes=base64.b64encode(file_contents) # Here you should use file_contents, not f.read()
payload= {
‘fileName’: file_name,
‘fileContent’: base64.b64encode(file_contents).decode(‘utf-8’), # Assuming file_contents is your binary file content
‘folderId’: folder_id
file_name = “potantial_delivered.csv”
with open(file_name, “rb”) as f:
base64_bytes=base64.b64encode(file_contents) # Here you should use file_contents, not f.read()
upload_to_ns(file_name, base64_bytes, folder_id)
Rookie Answered on August 2, 2023.
Add Comment

@yogiupadhyay Thank you for your response. I waited two years for a solution. I will begin to implement asap. I’ll return to give an update on this.



Rookie Answered on August 3, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Become a Sponsor   Become a Sponsor