---
title: Upload File
slug: netsuite/upload-file
description: Learn how to upload files to NetSuite using the Upload File request with these easy-to-follow instructions and code examples. Discover the parameters of the File object and how to upload attachments and URLs as files. Includes code snippets and response J
docTags: 
createdAt: 2023-04-24T05:03:43.000Z
---

When using the Upload File request, use requestJSON to pass the required file details. The response will have responseJSON, which stores the file response returned by NetSuite. This action will upload the file into the given file cabinet's folder.

***Note:&#x20;***&#x4E;etSuite has a 500k limitation for uploaded files. However, this can be overcome by using contentURL. This passes a URL link to the file, rather than the file itself.

The File object has the following parameters

| **Field Name** | **Data Type** | **Description**                                        |
| -------------- | ------------- | ------------------------------------------------------ |
| caption        | string        | Pass the file name                                     |
| content        | Blob          | Pass the blob content in the base64Encode format       |
| contentURL     | string        | Public URL of the content                              |
| folder         | LookupRecord  | Internal Id of the Folder                              |
| name           | string        | Provide the file name with the extension like Test.pdf |



The following is an example of uploading the Opportunity's attachment as a file to NetSuite.

:::CodeblockTabs
Request

```apex
Blob contentData;
Id currentOppId = [select Id, Name from opportunity where id='[your opportunity id]' LIMIT 1].Id;
for (ContentDocumentLink docLinks : [Select Id, ContentDocumentId from ContentDocumentLink where LinkedEntityId = :currentOppId LIMIT 1]) {
    for (ContentDocument docs : [Select Id, FileType, Title, FileExtension from ContentDocument where Id= :docLinks.ContentDocumentId]) {
        for (ContentVersion docVersion : [Select Id, VersionData from ContentVersion where ContentDocumentId =:docLinks.ContentDocumentId ]) {
            contentData = docVersion.VersionData;
        }
    }
}

Map<String, Object> nsFile = new Map<String, Object>();
nsFile.put('caption', 'Test');
nsFile.put('content', EncodingUtil.base64Encode(contentData));
nsFile.put('folder', new Map<String, Object>{'internalId'=>'800'});
nsFile.put('name', 'Test.pdf');

//  Initialize the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('files', new List<Object>{nsFile});
String reqJSON = JSON.serialize(requestJSONMap);
Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version', '1.0');
reqObj.put('action', 'uploadFile');
reqObj.put('requestJSON', reqJSON);

//  Place a request to Breadwinner Global API
Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
System.debug(resp);
```

Response

```json
{
   action=uploadFile,
   responseJSON={
      "fileInternalId":"1776",
      "errors":[],
      "status":"200"
   },
   timestamp=1682316853154,
   validRequest=true,
   version=1.0
}
```
:::

The following is an example of uploading a URL as a file to NetSuite.

:::CodeblockTabs
Request

```apex
Map<String, Object> nsFile = new Map<String, Object>();
nsFile.put('caption', 'Test');
nsFile.put('contentURL', 'https://resources.docs.salesforce.com/latest/latest/en-us/sfdc/pdf/basics.pdf');
nsFile.put('folder', new Map<String, Object>{'internalId'=>'800'});
nsFile.put('name', 'Test.pdf');

//  Initialize the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('files', new List<Object>{nsFile});
String reqJSON = JSON.serialize(requestJSONMap);
Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version', '1.0');
reqObj.put('action', 'uploadFile');
reqObj.put('requestJSON', reqJSON);

//  Place a request to Breadwinner Global API
Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
System.debug(resp);
```

Response

```json
{
   action=uploadFile,
   responseJSON={
      "fileInternalId":"1876",
      "errors":[],
      "status":"200"
   },
   timestamp=1682327380844,
   validRequest=true,
   version=1.0
}
```
:::

