Server Response Write File Method in SuiteScript

The writeFile method allows SuiteScript to send files as HTTP responses. Learn about its parameters and error handling.

·2 min read·View Oracle Docs

The writeFile method in SuiteScript serves a crucial role in HTTP responses by enabling scripts to write files back to the client. This method is especially useful for server scripts that need to deliver file content directly to users.

Method Description

The writeFile method is part of the http.ServerResponse object and is responsible for writing a file to the response stream. This function ensures that the file is appropriately handled and delivered to the requesting client.

Returns

  • Type: void

Supported Script Types

  • Server scripts are the only types that support this method. For further details, refer to the SuiteScript 2.x Script Types.

Governance

  • This method does not have any specific governance limitations.

Module

  • The method belongs to the N/http Module.

Parameters

The options parameter, a JavaScript object, is essential for the writeFile method's functionality. Here are its components:

ParameterTypeRequired / OptionalDescription
options.filefile.FileRequiredA file.File object that represents the file to be written.
options.isInlinebooleanOptionalWhen set to true, the file is treated as inline content. The default is false.

Error Handling

The following errors may be thrown when using the writeFile method:

Error CodeMessageThrown If
SSS_MISSING_REQD_ARGUMENTMissing a required argument: {param name}The options.file parameter is not supplied.
WRONG_PARAMETER_TYPE{param name}The provided value for options.file is not a valid file.File object.

Syntax

The code example below demonstrates the syntax for using the writeFile method:

suitescript
1// Assume myFileObj is an instance of a file.File object
2deliverFile(serverResponse) {
3 serverResponse.writeFile({
4 file: myFileObj,
5 isInline: true
6 });
7}

Related Topics

For more details about related topics, explore:

This method is vital for developers working with server-side scripts in SuiteScript, providing a seamless way to manage file responses.

Key Takeaways

  • The writeFile method allows writing files to HTTP responses in SuiteScript.
  • It requires the options.file parameter to be provided.
  • Error handling is essential to ensure the correct file type and presence of required parameters.

Frequently Asked Questions (4)

Does the writeFile method require any specific permissions or governance limitations?
The writeFile method does not have any specific governance limitations indicated in the article. Permissions typically depend on the context in which the server script runs.
Can the writeFile method be used in client scripts?
No, the writeFile method is only supported in server scripts. Client scripts are not applicable for this method.
What parameter is essential for the writeFile method to function correctly?
The options.file parameter is required, and it must be a valid file.File object. Omitting this parameter will result in a SSS_MISSING_REQD_ARGUMENT error.
What happens if the options.file parameter is not a valid file.File object?
If the provided value for the options.file parameter is not a valid file.File object, a WRONG_PARAMETER_TYPE error will be thrown.
Source: Errors Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Integration

View all Integration articles →