Latest version

Upload part of file

put
https://{box-upload-server}/api/2.0
/files/upload_sessions/:upload_session_id

Uploads a chunk of a file for an upload session.

The actual endpoint URL is returned by the Create upload session and Get upload session endpoints.

Request

bearer [ACCESS_TOKEN]
application/octet-stream

Request Headers

stringin headerrequired
bytes 8388608-16777215/445856194

The byte range of the chunk.

Must not overlap with the range of a part already uploaded this session. Each part’s size must be exactly equal in size to the part size specified in the upload session that you created. One exception is the last part of the file, as this can be smaller.

When providing the value for content-range, remember that:

  • The lower bound of each part's byte range must be a multiple of the part size.
  • The higher bound must be a multiple of the part size - 1.
stringin headerrequired
sha=fpRyg5eVQletdZqEKaFlqwBXJzM=

The RFC3230 message digest of the chunk uploaded.

Only SHA1 is supported. The SHA1 digest must be base64 encoded. The format of this header is as sha=BASE64_ENCODED_DIGEST.

To get the value for the SHA digest, use the openSSL command to encode the file part: openssl sha1 -binary <FILE_PART_NAME> | base64

Path Parameters

stringin pathrequired
D5E3F7A

The ID of the upload session.

Request Body

binaryin bodyrequired

The binary content of the file

Response

application/jsonUploaded part

Chunk has been uploaded successfully.

application/jsonClient error

Returns an error if the chunk conflicts with another chunk previously uploaded.

application/jsonClient error

Returns an error if a precondition was not met.

application/jsonClient error

Returns an error if the content range does not match a specified range for the session.

application/jsonClient error

An unexpected client error.

put
Upload part of file
You can now try out some of our APIs live, right here in the documentation.
Log in

Request Example

cURL
curl -i -X PUT "https://upload.box.com/2.0/files/upload_sessions/F971964745A5CD0C001BBE4E58196BFD" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
     -H "digest: sha=fpRyg5eVQletdZqEKaFlqwBXJzM=" \
     -H "content-range: bytes 8388608-16777215/445856194" \
     -H "content-type: application/octet-stream" \
     --data-binary @<FILE_NAME>
TypeScript Gen
await client.chunkedUploads.uploadFilePart(
  acc.uploadSessionId,
  generateByteStreamFromBuffer(chunkBuffer),
  {
    digest: digest,
    contentRange: contentRange,
  } satisfies UploadFilePartHeadersInput,
);
Python Gen
client.chunked_uploads.upload_file_part(
    acc.upload_session_id,
    generate_byte_stream_from_buffer(chunk_buffer),
    digest,
    content_range,
)
.NET Gen
await client.ChunkedUploads.UploadFilePartAsync(uploadSessionId: acc.UploadSessionId, requestBody: Utils.GenerateByteStreamFromBuffer(buffer: chunkBuffer), headers: new UploadFilePartHeaders(digest: digest, contentRange: contentRange));
Swift Gen (Beta)
try await client.chunkedUploads.uploadFilePart(uploadSessionId: acc.uploadSessionId, requestBody: Utils.generateByteStreamFromBuffer(buffer: chunkBuffer), headers: UploadFilePartHeaders(digest: digest, contentRange: contentRange))
Java
//Reading a large file
FileInputStream fis = new FileInputStream("My_Large_File.txt");
//Create the digest input stream to calculate the digest for the whole file.
DigestInputStream dis = new DigestInputStream(fis, digest);

List<BoxFileUploadSessionPart> parts = new ArrayList<BoxFileUploadSessionPart>();

//Get the part size. Each uploaded part should match the part size returned as part of the upload session.
//The last part of the file can be less than part size if the remaining bytes of the last part is less than
//the given part size
long partSize = sessionInfo.getPartSize();
//Start byte of the part
long offset = 0;
//Overall of bytes processed so far
long processed = 0;
while (processed < fileSize) {
    long diff = fileSize - processed;
    //The size last part of the file can be less than the part size.
    if (diff < partSize) {
        partSize = diff;
    }

    //Upload a part. It can be uploaded asynchorously
    BoxFileUploadSessionPart part = session.uploadPart(dis, offset, (int)partSize, fileSize);
    parts.add(part);

    //Increase the offset and proceesed bytes to calculate the Content-Range header.
    processed += partSize;
    offset += partSize;
}
Python
upload_session = client.upload_session('11493C07ED3EABB6E59874D3A1EF3581')
offset = upload_session.part_size * 3
total_size = 26000000
part_bytes = b'abcdefgh'
part = upload_session.upload_part_bytes(part_bytes, offset, total_size)
print(f'Successfully uploaded part ID {part["part_id"]}')
Node
// Upload the part starting at byte offset 8388608 to upload session '93D9A837B45F' with part ID 'feedbeef'
client.files.uploadPart('93D9A837B45F', part, 8388608, 2147483648, {part_id: 'feedbeef'}, callback);

Response Example

{
  "part": {
    "offset": 16777216,
    "part_id": "6F2D3486",
    "sha1": "134b65991ed521fcfe4724b7d814ab8ded5185dc",
    "size": 3222784
  }
}