The module N/file can be used to fetch the details from the file.
Normally we can fetch the content by file.getContent() property and have a 10 MB file size limitation.
If we have more than 10 MB file can be iterated by line by line using file.lines.iterator() propety.
File.lines.iterator()
var iterator = invoiceFile.lines.iterator();
//Skip the first line (CSV header)
iterator.each(function () {return false;});
iterator.each(function (line)
{
// This function updates the total by
// adding the amount on each line to it
var lineValues = line.value.split(‘,’);
var lineAmount = parseFloat(lineValues[1]);
if (!lineAmount)
throw error.create({
name: 'INVALID_INVOICE_FILE',
message: 'Invoice file contained non-numeric value for total: ' + lineValues[1]
});
total += lineAmount;
return true;
});
Note
Method used to pass the next line as an argument to a developer-defined function. You can call this method multiple times to loop over the file contents as a stream.
Return false to stop the loop. Return true to continue the loop. By default, false is returned when the end of the file is reached.
This method can be used on text or .csv files.
Important
Content held in memory is limited to 10MB. Therefore, each line must be less than 10MB.