Chunked Upload with SDKs

Chunked Upload with SDKs

The Box SDKs make it possible to perform a chunked upload with the built-in SDK methods.

Java
File myFile = new File("My Large_File.txt"); 
FileInputStream stream = new FileInputStream(myFile);

BoxFolder rootFolder = BoxFolder.getRootFolder(api);
BoxFile.Info fileInfo = rootFolder.uploadLargeFile(inputStream, "My_Large_File.txt", myFile.length());
Python
chunked_uploader = client.file('12345').get_chunked_uploader('/path/to/file')
uploaded_file = chunked_uploader.start()
print('File "{0}" uploaded to Box with file ID {1}'.format(uploaded_file.name, uploaded_file.id))
Node
// Upload a 2GB file "huge.pdf" into folder 12345
var stream = fs.createReadStream('huge.pdf');
client.files.getChunkedUploader('12345', 2147483648, 'huge.pdf', stream)
	.then(uploader => uploader.start())
	.then(file => {
		/* file -> {
			total_count: 1,
			entries: 
			[ { type: 'file',
				id: '11111',
				file_version: 
					{ type: 'file_version',
					id: '22222',
					sha1: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33' },
				sequence_id: '0',
				etag: '0',
				sha1: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33',
				name: 'huge.pdf',
				description: '',
				size: 2147483648,
				path_collection: 
					{ total_count: 1,
					entries: 
					[ { type: 'folder',
						id: '12345',
						sequence_id: null,
						etag: null,
						name: 'My Folder' } ] },
				created_at: '2017-05-16T15:18:02-07:00',
				modified_at: '2017-05-16T15:18:02-07:00',
				trashed_at: null,
				purged_at: null,
				content_created_at: '2017-05-16T15:18:02-07:00',
				content_modified_at: '2017-05-16T15:18:02-07:00',
				created_by: 
					{ type: 'user',
					id: '33333',
					name: 'Test User',
					login: 'test@example.com' },
				modified_by: 
					{ type: 'user',
					id: '33333',
					name: 'Test User',
					login: 'test@example.com' },
				owned_by: 
					{ type: 'user',
					id: '33333',
					name: 'Test User',
					login: 'test@example.com' },
				shared_link: null,
				parent: 
					{ type: 'folder',
					id: '12345',
					sequence_id: null,
					etag: null,
					name: 'My Folder' }
				item_status: 'active' } ] }
		*/
	});

The SDKs also support uploading new versions of files through similar methods.

Java
File myFile = new File("My Large_File.txt"); 
FileInputStream stream = new FileInputStream(myFile);

String fileID = "12345";
BoxFile file = new BoxFile(api, fileID);
BoxFile.Info fileInfo = file.uploadLargeFile(inputStream, myFile.length());
Node
// Upload a new 2GB version of file 98765
var stream = fs.createReadStream('huge.pdf');
client.files.getNewVersionChunkedUploader('11111', 2147483648, stream)
	.then(uploader => uploader.start())
	.then(file => {
		/* file -> {
			total_count: 1,
			entries: 
			[ { type: 'file',
				id: '11111',
				file_version: 
					{ type: 'file_version',
					id: '22222',
					sha1: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33' },
				sequence_id: '0',
				etag: '0',
				sha1: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33',
				name: 'huge.pdf',
				description: '',
				size: 2147483648,
				path_collection: 
					{ total_count: 1,
					entries: 
					[ { type: 'folder',
						id: '12345',
						sequence_id: null,
						etag: null,
						name: 'My Folder' } ] },
				created_at: '2017-05-16T15:18:02-07:00',
				modified_at: '2017-05-21T15:18:02-07:00',
				trashed_at: null,
				purged_at: null,
				content_created_at: '2017-05-16T15:18:02-07:00',
				content_modified_at: '2017-05-21:18:02-07:00',
				created_by: 
					{ type: 'user',
					id: '33333',
					name: 'Test User',
					login: 'test@example.com' },
				modified_by: 
					{ type: 'user',
					id: '33333',
					name: 'Test User',
					login: 'test@example.com' },
				owned_by: 
					{ type: 'user',
					id: '33333',
					name: 'Test User',
					login: 'test@example.com' },
				shared_link: null,
				parent: 
					{ type: 'folder',
					id: '12345',
					sequence_id: null,
					etag: null,
					name: 'My Folder' }
				item_status: 'active' } ] }
		*/
	});