b2_list_parts
Lists the parts that have been uploaded for a large file that has not been finished yet.
This call returns at most 1000 entries, but it can be called repeatedly to scan through all of the parts for an upload.
Request
Request HTTP Headers
Authorization
required
The account authorization token returned by b2_authorize_account
.
The token must have the writeFiles
capability.
Request HTTP Message Body Parameters
fileId
required
The ID returned by b2_start_large_file
.
This is the file whose parts will be listed.
startPartNumber
optional
The first part to return. If there is a part with this number, it will be returned as the first in the list. If not, the returned list will start with the first part number after this one.
maxPartCount
optional
The maximum number of parts to return from this call. The default value is 100, and the maximum allowed is 1000.
Response
Response HTTP Status 200
List of parts as JSON:
parts
An array of objects, each one describing one part. (See below.)
nextPartNumber
What to pass in to startPartNumber for the next search to continue where this one left off, or null if there are no more files. Note this this may not be the number of an actual part, but using it is guaranteed to find the next file in the bucket.
And each of the parts is:
fileId
The file ID for uploading this file.
partNumber
Which part this is.
contentLength
The number of bytes stored in the part.
contentSha1
The SHA1 of the bytes stored in the part.
contentMd5
optional
The MD5 of the bytes stored in the part. Not all parts have an MD5 checksum, so this field is optional, and set to null for parts that do not have one.
serverSideEncryption
optional
When the part is encrypted with Server-Side Encryption, the mode ("SSE-B2" or "SSE-C") and algorithm used to encrypt the data.
uploadTimestamp
This is a UTC time when this part was uploaded. It is a base 10 number of milliseconds since midnight, January 1, 1970 UTC. This fits in a 64 bit integer such as the type "long" in the programming language Java. It is intended to be compatible with Java's time long. For example, it can be passed directly into the java call Date.setTime(long time).
Response Errors
If possible the server will return a JSON error structure. Errors include:
status |
code |
description |
---|---|---|
400 |
bad_bucket_id |
The requested bucket ID does not match an existing bucket. |
400 |
bad_request |
The request had the wrong fields or illegal values. The message returned with the error will describe the problem. |
400 |
cannot_delete_non_empty_bucket |
A bucket must be empty before it can be deleted. To delete this bucket, first remove all of the files in the bucket, then try the delete operation again. |
401 |
bad_auth_token |
The auth token used is not valid. Call b2_authorize_account again to either get a new one, or an error message describing the problem. |
401 |
expired_auth_token |
The auth token used has expired. Call b2_authorize_account again to get a new one. |
401 |
unauthorized |
The auth token used is valid, but does not authorize this call with these parameters. The capabilities of an auth token are determined by the application key used with b2_authorize_account. |
403 |
transaction_cap_exceeded |
Transaction cap exceeded. To increase your cap, sign in to your B2 Cloud Storage account online. Then select the Caps & Alerts link in the B2 Cloud Storage section of the sidebar. |
API Versions
v1: Application keys (July 26, 2018)
Incompatible change: After calling b2_authorize_account with an application key that does not have the right permissions, this call will return a 401 Unauthorized.
v1: Original release (September 22, 2015)
Sample Code
Code
FILE_ID=''; # Provided by b2_start_large_file
ACCOUNT_AUTHORIZATION_TOKEN=''; # Provided by b2_authorize_account
API_URL=''; # Provided by b2_authorize_account
curl \
-H "Authorization: $ACCOUNT_AUTHORIZATION_TOKEN" \
-d "`printf '{"fileId":"%s"}' $FILE_ID`" \
"$API_URL/b2api/v2/b2_list_parts"
Output
start: {
"nextPartNumber": null,
"parts": [
{
"contentLength": 100000000,
"contentSha1": "062685a84ab248d2488f02f6b01b948de2514ad8",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 1,
"uploadTimestamp": 1462212185000
},
{
"contentLength": 100000000,
"contentSha1": "cf634751c3d9f6a15344f23cbf13f3fc9542addf",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 2,
"uploadTimestamp": 1462212296000
},
{
"contentLength": 8158554,
"contentSha1": "00ad164147cbbd60aedb2b04ff66b0f74f962753",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 3,
"uploadTimestamp": 1462212327000
}
]
}
Code
import java.io.*;
import java.util.*;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.json.*;
String accountAuthorizationToken = ""; // Provided by b2_authorize_account
String apiUrl = ""; // Provided by b2_authorize_account
String fileId = ""; // Provided by b2_start_large_file
// Get Upload Part URL
// Create a model
JsonObject getUploadPartJsonObj = Json.createObjectBuilder()
.add("fileId", fileId)
.build();
// Write the model to stream
StringWriter sw = new StringWriter();
JsonWriter jw = Json.createWriter(sw);
jsonWriter.writeObject(getUploadPartJsonObj);
jsonWriter.close();
postData = sw.toString();
try {
URL url = new URL(apiUrl + "/b2api/v2/b2_list_parts");
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Authorization", accountAuthorizationToken);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Charset", "UTF-8");
connection.setRequestProperty("Content-Length", Integer.toString(postData.length()));
connection.setDoOutput(true);
DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream());
dataOutputStream.writeBytes(postData);
dataOutputStream.close();
String jsonResponse = myInputStreamReader(connection.getInputStream());
System.out.println(jsonResponse);
} catch (Exception e) {
e.printStackTrace();
} finally {
connection.disconnect();
}
// Input stream reader example.
static public String myInputStreamReader(InputStream in) throws IOException {
InputStreamReader reader = new InputStreamReader(in);
StringBuilder sb = new StringBuilder();
int c = reader.read();
while (c != -1) {
sb.append((char)c);
c = reader.read();
}
reader.close();
return sb.toString();
}
Output
start: {
"nextPartNumber": null,
"parts": [
{
"contentLength": 100000000,
"contentSha1": "062685a84ab248d2488f02f6b01b948de2514ad8",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 1,
"uploadTimestamp": 1462212185000
},
{
"contentLength": 100000000,
"contentSha1": "cf634751c3d9f6a15344f23cbf13f3fc9542addf",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 2,
"uploadTimestamp": 1462212296000
},
{
"contentLength": 8158554,
"contentSha1": "00ad164147cbbd60aedb2b04ff66b0f74f962753",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 3,
"uploadTimestamp": 1462212327000
}
]
}
Code
import base64
import json
import urllib2
account_authorization_token = "" # Provided by b2_authorize_account
api_url = "" # Provided by b2_authorize_account
file_id = "" # Provided by b2_start_large_file
request = urllib2.Request(
'%s/b2api/v2/b2_list_parts' % api_url,
json.dumps({ 'fileId': file_id }),
headers = { 'Authorization': account_authorization_token }
)
response = urllib2.urlopen(request)
response_data = json.loads(response.read())
response.close()
Output
file ID: 4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001
part number: 1
content length: 100000000
content sha1: 062685a84ab248d2488f02f6b01b948de2514ad8
upload timestamp: 1462212185000
file ID: 4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001
part number: 2
content length: 100000000
content sha1: cf634751c3d9f6a15344f23cbf13f3fc9542addf
upload timestamp: 1462212296000
file ID: 4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001
part number: 3
content length: 8158554
content sha1: 00ad164147cbbd60aedb2b04ff66b0f74f962753
upload timestamp: 1462212327000
Code
import Foundation
let apiUrl = "" // Provided by b2_authorize_account
let accountAuthorizationToken = "" // Provided by b2_authorize_account
let fileId = "" // Provided by b2_start_large_file
// Create the request
var request = URLRequest(url: URL(string: "\(apiUrl)/b2api/v2/b2_list_parts")!)
request.httpMethod = "POST"
request.addValue(accountAuthorizationToken, forHTTPHeaderField: "Authorization")
request.httpBody = "{\"fileId\":\"\(fileId)\"}".data(using: .utf8)
// Create the task
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
if let jsonData = data {
let json = String(data: jsonData, encoding: .utf8)
print("\(json!)")
}
}
// Start the task
task.resume()
// Swift 4.1 (swiftlang-902.0.48 clang-902.0.37.1) Xcode 9.3.1 (9E501)
Output
start: {
"nextPartNumber": null,
"parts": [
{
"contentLength": 100000000,
"contentSha1": "062685a84ab248d2488f02f6b01b948de2514ad8",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 1,
"uploadTimestamp": 1462212185000
},
{
"contentLength": 100000000,
"contentSha1": "cf634751c3d9f6a15344f23cbf13f3fc9542addf",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 2,
"uploadTimestamp": 1462212296000
},
{
"contentLength": 8158554,
"contentSha1": "00ad164147cbbd60aedb2b04ff66b0f74f962753",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 3,
"uploadTimestamp": 1462212327000
}
]
}
Code
require 'json'
require 'net/http'
require 'digest/sha1'
account_authorization_token = "" # Provided by b2_authorize_account
api_url = "" # Provided by b2_authorize_account
file_id = "" # Provided by b2_start_large_file
uri = URI.join("#{api_url}/b2api/v2/b2_list_parts")
req = Net::HTTP::Post.new(uri)
req.add_field("Authorization","#{account_authorization_token}")
req.body = "{\"fileId\":\"#{file_id}\"}"
http = Net::HTTP.new(req.uri.host, req.uri.port)
http.use_ssl = true
res = http.start {|http| http.request(req)}
case res
when Net::HTTPSuccess then
json = res.body
puts "start: #{json}"
when Net::HTTPRedirection then
fetch(res['location'], limit - 1)
else
res.error!
end
Output
start: {
"nextPartNumber": null,
"parts": [
{
"contentLength": 100000000,
"contentSha1": "062685a84ab248d2488f02f6b01b948de2514ad8",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 1,
"uploadTimestamp": 1462212185000
},
{
"contentLength": 100000000,
"contentSha1": "cf634751c3d9f6a15344f23cbf13f3fc9542addf",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 2,
"uploadTimestamp": 1462212296000
},
{
"contentLength": 8158554,
"contentSha1": "00ad164147cbbd60aedb2b04ff66b0f74f962753",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 3,
"uploadTimestamp": 1462212327000
}
]
}
Code
using System;
using System.Net;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;
String apiUrl = ""; // Provided by b2_authorize_account
String authorizationToken = ""; // Provided by b2_authorize_account
String fileId = ""; // Provided by b2_start_large_file
// Get Upload URL
String getUploadUrlJsonStr = "{\"fileId\":\"" + fileId + "\"}";
byte[] getUloadUrlJsonData = Encoding.UTF8.GetBytes(getUploadUrlJsonStr);
HttpWebRequest getUploadUrlRequest = (HttpWebRequest)WebRequest.Create(apiUrl + "/b2api/v2/b2_list_parts");
getUploadUrlRequest.Method = "POST";
getUploadUrlRequest.Headers.Add("Authorization", authorizationToken);
getUploadUrlRequest.ContentType = "application/json; charset=utf-8";
getUploadUrlRequest.ContentLength = getUloadUrlJsonData.Length;
using (Stream stream = getUploadUrlRequest.GetRequestStream())
{
stream.Write(getUloadUrlJsonData, 0, getUloadUrlJsonData.Length);
stream.Close();
}
// Handle the response and print the json
try
{
HttpWebResponse getUploadUrlResponse = (HttpWebResponse)getUploadUrlRequest.GetResponse();
using(StringReader responseReader = new StreamReader(getUploadUrlResponse.GetResponseStream()))
{
String json = responseReader.ReadToEnd();
Console.WriteLine(json);
}
getUploadUrlResponse.Close();
}
catch (WebException e)
{
using (HttpWebResponse errorResponse = (HttpWebResponse)e.Response)
{
Console.WriteLine("Error code: {0}", errorResponse.StatusCode);
using (StreamReader reader = new StreamReader(errorResponse.GetResponseStream()))
{
String text = reader.ReadToEnd();
Console.WriteLine(text);
}
}
}
Output
start: {
"nextPartNumber": null,
"parts": [
{
"contentLength": 100000000,
"contentSha1": "062685a84ab248d2488f02f6b01b948de2514ad8",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 1,
"uploadTimestamp": 1462212185000
},
{
"contentLength": 100000000,
"contentSha1": "cf634751c3d9f6a15344f23cbf13f3fc9542addf",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 2,
"uploadTimestamp": 1462212296000
},
{
"contentLength": 8158554,
"contentSha1": "00ad164147cbbd60aedb2b04ff66b0f74f962753",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 3,
"uploadTimestamp": 1462212327000
}
]
}
Code
<?php
$api_url = ""; // Provided by b2_authorize_account
$account_auth_token = ""; // Provided by b2_authorize_account
$file_id = ""; // Provided by b2_start_large_file
// Construct post info
$data = array("fileId" => $file_id);
$post_fields = json_encode($data);
$session = curl_init($api_url . "/b2api/v2/b2_list_parts");
curl_setopt($session, CURLOPT_POSTFIELDS, $post_fields);
// Add headers
$headers = array();
$headers[] = "Accept: application/json";
$headers[] = "Authorization: " . $account_auth_token;
print_r ($headers);
curl_setopt($session, CURLOPT_HTTPHEADER, $headers); // Add headers
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Receive server response
$server_output = curl_exec($session);
curl_close ($session);
print $server_output;
?>
Output
start: {
"nextPartNumber": null,
"parts": [
{
"contentLength": 100000000,
"contentSha1": "062685a84ab248d2488f02f6b01b948de2514ad8",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 1,
"uploadTimestamp": 1462212185000
},
{
"contentLength": 100000000,
"contentSha1": "cf634751c3d9f6a15344f23cbf13f3fc9542addf",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 2,
"uploadTimestamp": 1462212296000
},
{
"contentLength": 8158554,
"contentSha1": "00ad164147cbbd60aedb2b04ff66b0f74f962753",
"fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
"partNumber": 3,
"uploadTimestamp": 1462212327000
}
]
}