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.

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.

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

message

400

bad_request

Invalid fileId: <fileId>

400

bad_request

not an active upload: <fileId>

400

bad_request

startPartNumber must be in the range 1 - 10000

400

bad_request

maxPartCount must be in the range 1 - 1000

400

bad_request

Wrong host name for request

401

missing_auth_token

Authorization token is missing

401

expired_auth_token

Authorization token has expired

401

bad_auth_token

Invalid authorization token

401

bad_auth_token

Authorization token for wrong cluster

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/v1/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/v1/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/v1/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
let session = NSURLSession.sharedSession()
let request = NSMutableURLRequest(URL:NSURL(string: "\(apiUrl)")!.URLByAppendingPathComponent("/b2api/v1/b2_list_parts"))
request.HTTPMethod = "POST"
request.addValue(accountAuthorizationToken, forHTTPHeaderField: "Authorization")
request.HTTPBody = "{\"fileId\":\"\(fileId)\"}".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
let task = session.dataTaskWithRequest(request, completionHandler:{ (data: NSData?, response: NSURLResponse?, error: NSError?) -> Void in
    if let jsonData = data {
        let json = NSString(data: jsonData, encoding:NSUTF8StringEncoding)
        print(json)
    }
})
task.resume()

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/v1/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/v1/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/v1/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
    }
  ]
}