Download a File Using RESTlet

The  RESTlet script receives a POST request with data containing a file ID. It loads the specified file, checks if its size is less than 10MB, and returns either the file content or a message indicating that the file is larger than 10MB.
/**
 * @NApiVersion 2.x
 * @NScriptType Restlet
 */
define(['N/file'],
    function(file) {
         function post(dataIn) {
             if(dataIn){
               var recFile = file.load({
                id : dataIn.id
               });

               if (recFile.size < 10485760){
                   return recFile.getContents();
               } else {
                 return 'File more than 10MB';
               }
             }
        }

        return {
            post : post
        };
    });
Run the RESTlet via POSTman using the below JSON

{id:"fileinternalId"}

Leave a comment

Your email address will not be published. Required fields are marked *