Box Developerドキュメント

SDKによる分割アップロード

ガイド アップロード 分割アップロード SDKによる分割アップロード

SDKによる分割アップロード

Box SDKにより、組み込みメソッドを使用して分割アップロードを実行できるようになります。

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
# uploads large file to a root folder 
chunked_uploader = client.folder('0').get_chunked_uploader(file_path='/path/to/file.txt', file_name='new_name.txt')
uploaded_file = chunked_uploader.start()
print(f'File "{uploaded_file.name}" uploaded to Box with file ID {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' } ] }
		*/
	});

また、同様の方法によるファイルの新しいバージョンのアップロードもサポートされます。

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());
Python
file_name = 'large_file.mp4'
test_file_path = '/path/to/large_file.mp4'
total_size = os.stat(test_file_path).st_size
destination_folder_id = '0'
try:
  client.folder(destination_folder_id).preflight_check(size=total_size, name=file_name)
except BoxAPIException as e:
  print(f'File {file_name} cannot be uploaded to folder with id: {destination_folder_id}. Reason: {e.message}')
.NET
var progress = new Progress<BoxProgress>(val => {
    Console.WriteLine("Uploaded {0}%", val.progress);
});
using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
{
    string parentFolderId = "0";
    var bFile = await client.FilesManager.UploadUsingSessionAsync(fileStream, "File v2.pdf", parentFolderId, null, progress);
    Console.WriteLine("{0} uploaded to folder: {1} as file: {2}", filePath, parentFolderId, bFile.Id);
}
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' } ] }
		*/
	});