Has anyone in the NS developer world ever push/upload a csv file from external drive into Netsuite file cabinet using a RESTlet
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:
- 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.
- Use a POST request to send it to your Restlet
- 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)
- Using the File API, write it to the file system.
- 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.
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.
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.
2ps
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.
soakes55
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 )
break;
default:
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 }
}
}