Documentation Index
Fetch the complete documentation index at: https://developer.box.com/llms.txt
Use this file to discover all available pages before exploring further.
Box is a cloud-based, intelligent content management and file sharing platform for storing, accessing, and collaborating on content from anywhere.
Sign up for a free account
Confirm your email address to activate your developer account.
Upload a file to Box
The Upload file endpoint allows you to upload a single file to Box through the upload domain https://upload.box.com/api/2.0/files/content.
The maximum file size is 50MB. For larger files, use the .
A pre-built application is created for you to get started. Create a developer token to authenticate your requests. Go to the Developer Console > your pre-built application and find the App Details section. Locate the Developer Token field, select Generate Developer Token, and copy it.
Developer tokens expire one hour after you generate them.
We prepared an example invoice document for you to upload. Download it and save it as invoice.pdf.
Python
Node.js
Swift
Java
.NET
Create and activate a Python virtual environment.python3 -m venv .venv
source .venv/bin/activate
Install the Box Python SDK by running the following command using .Make sure you use the most up-to-date version number of the Python SDK. Refer to the
.
Obtain a client with your developer token:from box_sdk import BoxClient, BoxDeveloperTokenAuth
auth = BoxDeveloperTokenAuth(token="YOUR_DEVELOPER_TOKEN")
client = BoxClient(auth=auth)
Never commit .env files to version control. Add .env to your .gitignore.
Then call the upload API as follows.client.uploads.upload_file(
UploadFileAttributes(
name="invoice.pdf", parent=UploadFileAttributesParentField(id="0")
),
file_content_stream,
)
Execute the script to upload the file. Install the Box Node.js SDK by running the following command using .A pre-built application is created for you to get started. Create a developer token to authenticate your requests. Go to the Developer Console > your pre-built application and find the App Details section. Locate the Developer Token field, select Generate Developer Token, and copy it.Developer tokens expire one hour after you generate them.
const fs = require('fs');
const attrs = { name: 'invoice.pdf', parent: { id: '0' } };
const body = {
attributes: attrs,
file: fs.createReadStream('invoice.pdf'),
};
const files = await client.uploads.uploadFile(body);
const file = files.entries[0];
console.log(`File uploaded with id ${file.id}, name ${invoice.pdf}`);
Execute the script to upload the file. Install the Box Swift SDK by running the following command using .A pre-built application is created for you to get started. Create a developer token to authenticate your requests. Go to the Developer Console > your pre-built application and find the App Details section. Locate the Developer Token field, select Generate Developer Token, and copy it.Developer tokens expire one hour after you generate them.
Create a request body with the required parameters: attributes (name and parent id) and a file stream.// Create InputStream for a file based on URL
guard let fileStream = InputStream(url: URL(string: "https://cloud.box.com/s/lai54mzu8a7nip4k1dlboiakfu4p94k1")!) else {
fatalError("Could not read a file")
}
// Create a request body with the required parameters
let requestBody = UploadFileRequestBody(
attributes: UploadFileRequestBodyAttributesField(
name: "invoice.pdf",
parent: UploadFileRequestBodyAttributesParentField(id: "0")
),
file: fileStream
)
// Call uploadFile method
let files = try await client.uploads.uploadFile(requestBody: requestBody)
// Print some data from the reponse
if let file = files.entries?[0] {
print("File uploaded with id \(file.id), name \(invoice.pdf!)")
}
Execute the script to upload the file. A pre-built application is created for you to get started. Create a developer token to authenticate your requests. Go to the Developer Console > your pre-built application and find the App Details section. Locate the Developer Token field, select Generate Developer Token, and copy it.Developer tokens expire one hour after you generate them.
GradleInstall the Box Java SDK by adding the following dependency to the build.gradle file.compile 'com.box:box-java-sdk:4.11.1'
Make sure you use the most up-to-date version number of the Java SDK. Refer to the
.
MavenThen add the following to Maven dependency.<dependency>
<groupId>com.box</groupId>
<artifactId>box-java-sdk</artifactId>
<version>4.11.1</version>
</dependency>
Pass new UploadFileRequestBody to client.getUploads().uploadFile: attributes (UploadFileRequestBodyAttributesField with name and UploadFileRequestBodyAttributesParentField for folder id) and an InputStream for the file bytes.client.getUploads().uploadFile(new UploadFileRequestBody(new UploadFileRequestBodyAttributesField(invoice.pdf, new UploadFileRequestBodyAttributesParentField("0")), fileContentStream))
Execute the script to upload the file. .NET FrameworkTo install the .NET SDK in the .NET framework, run the following command using
the package manager.PM> Install-Package Box.V2.Core
A pre-built application is created for you to get started. Create a developer token to authenticate your requests. Go to the Developer Console > your pre-built application and find the App Details section. Locate the Developer Token field, select Generate Developer Token, and copy it.Developer tokens expire one hour after you generate them.
.NET CoreTo install the .NET SDK in the .NET Core framework, run the following command using
the package manager.PM> Install-Package Box.V2.Core
Await client.Uploads.UploadFileAsync with new UploadFileRequestBody: UploadFileRequestBodyAttributesField (name and parent id) and a Stream (for example from File.OpenRead).using var fileContentStream = File.OpenRead("invoice.pdf");
var files = await client.Uploads.UploadFileAsync(
requestBody: new UploadFileRequestBody(
attributes: new UploadFileRequestBodyAttributesField(
name: "invoice.pdf",
parent: new UploadFileRequestBodyAttributesParentField(id: "0")),
file: fileContentStream));
var file = files.Entries[0];
Execute the script to upload the file.
List files in a folder
Now let’s list all files in the root folder.
Python
Node.js
Swift
Java
.NET
Run the following command to list all files in the root folder.client.folders.get_folder_items("0")
Run the following command to list all files in the root folder.await client.folders.getFolderItems("0");
Run the following command to list all files in the root folder.try await client.folders.getFolderItems(folderId: "0");
Run the following command to list all files in the root folder.client.getFolders().getFolderItems(folderOrigin.getId("0"));
Run the following command to list all files in the root folder.await client.Folders.GetFolderItemsAsync(folderId: ("0"));
Congratulations! 🎉 You’ve uploaded your first file to Box and listed all files in the root folder.
What’s next
Explore the following resources: