Join BoxWorks 2024 to discover what's possible with content and AI!

Register now!

Download file

get
https://api.box.com/2.0
/files/:file_id/content

Returns the contents of a file in binary format.

Request

bearer [ACCESS_TOKEN]
application/json

Path Parameters

stringin pathrequired
12345

The unique identifier that represents a file.

The ID for any file can be determined by visiting a file in the web application and copying the ID from the URL. For example, for the URL https://*.app.box.com/files/123 the file_id is 123.

Query Parameters

stringin queryoptional
c3FIOG9vSGV4VHo4QzAyg5T1JvNnJoZ3ExaVNyQWw6WjRsanRKZG5lQk9qUE1BVQ

An optional access token that can be used to pre-authenticate this request, which means that a download link can be shared with a browser or a third party service without them needing to know how to handle the authentication. When using this parameter, please make sure that the access token is sufficiently scoped down to only allow read access to that file and no other files or folders.

stringin queryoptional
4

The file version to download

Request Headers

stringin headeroptional
shared_link=[link]&shared_link_password=[password]

The URL, and optional password, for the shared link of this item.

This header can be used to access items that have not been explicitly shared with a user.

Use the format shared_link=[link] or if a password is required then use shared_link=[link]&shared_link_password=[password].

This header can be used on the file or folder shared, as well as on any files or folders nested within the item.

stringin headeroptional
bytes=0-1024

The byte range of the content to download.

The format bytes={start_byte}-{end_byte} can be used to specify what section of the file to download.

Response

application/octet-stream

Returns the requested file if the client has the follow redirects setting enabled to automatically follow HTTP 3xx responses as redirects. If not, the request will return 302 instead. For details, see the download file guide.

none

If the file is not ready to be downloaded yet Retry-After header will be returned indicating the time in seconds after which the file will be available for the client to download.

This response can occur when the file was uploaded immediately before the download request.

none

If the file is available for download the response will include a Location header for the file on dl.boxcloud.com.

The dl.boxcloud.com URL is not persistent and clients will need to follow the redirect to actually download the file.

application/jsonClient error

An unexpected client error.

get
Download file
You can now try out some of our APIs live, right here in the documentation.
Log in

Request Example

cURL
curl -i -L -X GET "https://api.box.com/2.0/files/12345/content" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
TypeScript Gen
const fs = require('fs');

const fileContent = await client.downloads.downloadFile('123456789');
const fileWriteStream = fs.createWriteStream('file.pdf');
fileContent.pipe(fileWriteStream);
Python Gen
import shutil
from io import BufferedIOBase

file_content_stream: BufferedIOBase = client.downloads.download_file(
    file_id="123456789"
)
with open("file.pdf", "wb") as f:
    shutil.copyfileobj(file_content_stream, f)
print('File was successfully downloaded as "file.pdf"')
.NET Gen
await client.Downloads.DownloadFileAsync(fileId: uploadedFile.Id);
Java
BoxFile file = new BoxFile(api, "id");
BoxFile.Info info = file.getInfo();

FileOutputStream stream = new FileOutputStream(info.getName());
file.download(stream);
stream.close();
Python
file_id = '11111'
file_content = client.file(file_id).content()
.NET
Stream fileContents = await client.FilesManager.DownloadStreamAsync(id: "11111");
Node
var fs = require('fs');
client.files.getReadStream('12345', null, function(error, stream) {

	if (error) {
		// handle error
	}

	// write the file to disk
	var output = fs.createWriteStream('/path/to/file');
	stream.pipe(output);
});
iOS
let url = FileManager.default.homeDirectoryForCurrentUser

let task: BoxDownloadTask = client.files.download(fileId: "11111", destinationURL: url) { (result: Result<Void, BoxSDKError>) in
    guard case .success = result else {
        print("Error downloading file")
        return
    }

    print("File downloaded successfully")
}

// To cancel download
if someConditionIsSatisfied {
    task.cancel()
}