ServerRequest.files

Note:

The content in this help topic pertains to SuiteScript 2.0.

Property Description

The server request files represented as object in ID-file.File pair.

Type

Object (read-only)

Supported Script Types

Server scripts

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

Module

N/https Module

Since

2015.2

Errors

Error Code

Thrown If

READ_ONLY_PROPERTY

You attempted to edit this property. This property is read-only.

Syntax
Important:

The following code sample shows the syntax for this member. They are not functional examples. For a complete script example, see N/https Module Script Samples.

          // Add additional code 
...
log.debug({
    title: 'Server Request Files',
    details: request.files
});
...
// Add additional code 

        
          var file = request.files['file_id']; 

        

Code Samples

Note:

This script sample uses the define function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript 2.x Global Objects

A sample form accepting a file as input then accessing its contents

          /**
 *@NApiVersion 2.x
 *@NScriptType Suitelet
 */
define(['N/ui/serverWidget', 'N/file'], function(serverWidget, file) {
    function onRequest(context) {
        var request = context.request;
        var response = context.response;
 
        if (request.method === 'GET')
        {
            var form = serverWidget.createForm({
                title : 'Sample Form'
            });
             
            form.addSubmitButton({
                id: 'submitBtn',
                label: 'Submit'
            });
             
            form.addField({
                id : 'custpage_file_csvinput',
                type : serverWidget.FieldType.FILE,
                label : 'CSV File'
            });
         
            response.writePage(form);
        }
        else if (request.method === 'POST')
        {
            var files = request.files; // {"custpage_file_csvinput": file.File Object}
 
            if (files)
            {
                var fileObj = files.custpage_file_csvinput;
                 
                var contents = fileObj.getContents()
                ...
                // Add additional code
            }
        }   
    }
 
    return {
        onRequest: onRequest
    };
}); 

        

Related Topics

https.ServerRequest
N/https Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices