b2_list_unfinished_large_files

Lists information about large file uploads that have been started, but have not been finished or canceled.

Uploads are listed in the order they were started, with the oldest one first.

This call returns at most 1000 entries, but it can be called repeatedly to scan through all of the uploads for a bucket. Each time you call, it returns a "nextFileId" that can be used as the starting point for the next call.

Request

Request HTTP Headers

Authorization

required

The account authorization token returned by b2_authorize_account. The token must have the listFiles capability.

Request HTTP Message Body Parameters

bucketId

required

The bucket to look for file names in.

namePrefix

optional

When a namePrefix is provided, only files whose names match the prefix will be returned. Whe using an application key that is restricted to a name prefix, you must provide a prefix here that is at least as restrictive.

startFileId

optional

The first upload to return. If there is an upload with this ID, it will be returned in the list. If not, the first upload after this the first one after this ID.

maxFileCount

optional

The maximum number of files to return from this call. The default value is 100, and the maximum allowed is 100.

Response

Response HTTP Status 200

List of unfinished large files as JSON:

files

An array of objects, each one describing one unfinished file. (See below.)

nextFileId

What to pass in to startUploadId 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 ID of an actual upload, but using it is guaranteed to find the next upload.

And each of the files is the standard file structure. Note that the action in each one will always be start, because they are all files that have been started but not finished.

accountId

The account that owns the file.

action

One of "start", "upload", "hide", "folder", or other values added in the future. "upload" means a file that was uploaded to B2 Cloud Storage. "start" means that a large file has been started, but not finished or canceled. "hide" means a file version marking the file as hidden, so that it will not show up in b2_list_file_names. "folder" is used to indicate a virtual folder when listing files.

bucketId

The bucket that the file is in.

contentLength

The number of bytes stored in the file. Only useful when the action is "upload". Always 0 when the action is "start", "hide", or "folder".

contentSha1

The SHA1 of the bytes stored in the file as a 40-digit hex string. Large files do not have SHA1 checksums, and the value is "none". The value is null when the action is "hide" or "folder".

contentMd5

optional

The MD5 of the bytes stored in the file as a 32-digit hex string. Not all files have an MD5 checksum, so this field is optional, and set to null for files that do not have one. Large files do not have MD5 checksums, and the value is null. The value is also null when the action is "hide" or "folder".

contentType

When the action is "upload" or "start", the MIME type of the file, as specified when the file was uploaded. For "hide" action, always "application/x-bz-hide-marker". For "folder" action, always null.

fileId

The unique identifier for this version of this file. Used with b2_get_file_info, b2_download_file_by_id, and b2_delete_file_version. The value is null when for action "folder".

fileInfo

The custom information that was uploaded with the file. This is a JSON object, holding the name/value pairs that were uploaded with the file.

fileName

The name of this file, which can be used with b2_download_file_by_name.

fileRetention

The Object Lock retention settings for this file, if any.
This field is filtered based on application key capabilities; the readFileRetentions capability is required to access the value. See Object Lock for more details on response structure.
This field is omitted when the action is "hide" or "folder".

legalHold

The Object Lock legal hold status for this file, if any.
This field is filtered based on application key capabilities; the readFileLegalHolds capability is required to access the value. See Object Lock for more details on response structure.
This field is omitted when the action is "hide" or "folder".

replicationStatus

The Replication Status for this file, if any. This will show either PENDING, COMPLETED, FAILED, or REPLICA. For details see Cloud Replication
This field is omitted when the file is not part of a replication rule.

serverSideEncryption

When the file is encrypted with Server-Side Encryption, the mode ("SSE-B2" or "SSE-C") and algorithm used to encrypt the data. If the file is not encrypted with Server-Side Encryption, then both mode and algorithm will be null.
This field is omitted when the action is "hide" or "folder".

uploadTimestamp

This is a UTC time when this file 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).
Always 0 when the action is "folder".

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

v2: Remove application key workaround, consistent file structures (Sept 13, 2018)

Listing file names will always return all of the file names you ask for. If your application key has a file name prefix restriction, and you ask for files outside that prefix, the call is unauthorized.

Listing file names will always return all of the file names you ask for. If your application key has a file name prefix restriction, and you ask for files outside that prefix, the call is unauthorized.

Now returns action ("start"), contentLength (0), and contentSha1 ("none") in files returned.

v1: Workaround for existing applications and application keys (August 9, 2018)

When using an application key with a file name prefix restriction, a request to list files will be filtered to show only files allowed by the application key.

v1: Application keys (July 26, 2018)

New optional namePrefix parameter to b2_list_unfinished_large_files so that you can restricted the results to just some files. This is especially useful with application keys that have file name restrictions.

v1: Original release (September 22, 2015)

Original release.

Sample Code

Code

ACCOUNT_AUTHORIZATION_TOKEN=''; # Provided by b2_authorize_account
API_URL=''; # Provided by b2_authorize_account
BUCKET_ID=''; # Provided by b2_create_bucket or b2_list_buckets
curl \
    -H "Authorization: $ACCOUNT_AUTHORIZATION_TOKEN" \
    -d "`printf '{"bucketId":"%s"}' $BUCKET_ID`" \
    "$API_URL/b2api/v2/b2_list_unfinished_large_files"

Output

{
  "files": [
    {
      "accountId": "ACCOUNT_ID",
      "action": "start",
      "bucketId": "b2f6f21365e1d29f6c580f18",
      "contentLength": 0,
      "contentSha1": "none",
      "contentType": "application/zip",
      "fileId": "4_zb2f6f21365e1d29f6c580f18_f20150c1fda5f4c8d_d20180919_m215912_c002_v0001110_t0050",
      "fileInfo": {},
      "fileName": "~/Downloads/512MB.zip",
      "fileRetention": {
        "isClientAuthorizedToRead": true,
        "value": {
          "mode": null,
          "retainUntilTimestamp": null
        }
      },
      "legalHold": {
        "isClientAuthorizedToRead": true,
        "value": null
      },
      "serverSideEncryption": {
        "algorithm": null,
        "mode": null
      },
      "uploadTimestamp": 1537394352000
    }
  ],
  "nextFileId": null
}

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 bucketId = ""; // Provided by b2_create_bucket or b2_list_buckets

// Get Upload Part URL
// Create a model
JsonObject getUploadPartJsonObj = Json.createObjectBuilder()
        .add("bucketId", bucketId)
        .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_unfinished_large_files");
    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

{
  "files": [
    {
      "accountId": "ACCOUNT_ID",
      "action": "start",
      "bucketId": "b2f6f21365e1d29f6c580f18",
      "contentLength": 0,
      "contentSha1": "none",
      "contentType": "application/zip",
      "fileId": "4_zb2f6f21365e1d29f6c580f18_f20150c1fda5f4c8d_d20180919_m215912_c002_v0001110_t0050",
      "fileInfo": {},
      "fileName": "~/Downloads/512MB.zip",
      "fileRetention": {
        "isClientAuthorizedToRead": true,
        "value": {
          "mode": null,
          "retainUntilTimestamp": null
        }
      },
      "legalHold": {
        "isClientAuthorizedToRead": true,
        "value": null
      },
      "serverSideEncryption": {
        "algorithm": null,
        "mode": null
      },
      "uploadTimestamp": 1537394352000
    }
  ],
  "nextFileId": null
}

Code

import base64
import json
import urllib2

account_authorization_token = "" # Provided by b2_authorize_account
api_url = "" # Provided by b2_authorize_account
bucket_id = "" # Provided by b2_create_bucket or b2_list_buckets

request = urllib2.Request(
    '%s/b2api/v2/b2_list_unfinished_large_files' % api_url,
    json.dumps({ 'bucketId': bucket_id }),
    headers = { 'Authorization': account_authorization_token }
)
response = urllib2.urlopen(request)
response_data = json.loads(response.read())
response.close() 

print 'account ID: ', response_data["files"][0]["accountId"]
print 'bucket ID: ', response_data["files"][0]["bucketId"]
print 'content type: ', response_data["files"][0]["contentType"]
print 'file ID: ', response_data["files"][0]["fileId"]
print 'file info: ', response_data["files"][0]["fileInfo"]
print 'file name: ', response_data["files"][0]["fileName"]
print 'upload timestamp: ', response_data["files"][0]["uploadTimestamp"]

Output

{
  "files": [
    {
      "accountId": "ACCOUNT_ID",
      "action": "start",
      "bucketId": "b2f6f21365e1d29f6c580f18",
      "contentLength": 0,
      "contentSha1": "none",
      "contentType": "application/zip",
      "fileId": "4_zb2f6f21365e1d29f6c580f18_f20150c1fda5f4c8d_d20180919_m215912_c002_v0001110_t0050",
      "fileInfo": {},
      "fileName": "~/Downloads/512MB.zip",
      "fileRetention": {
        "isClientAuthorizedToRead": true,
        "value": {
          "mode": null,
          "retainUntilTimestamp": null
        }
      },
      "legalHold": {
        "isClientAuthorizedToRead": true,
        "value": null
      },
      "serverSideEncryption": {
        "algorithm": null,
        "mode": null
      },
      "uploadTimestamp": 1537394352000
    }
  ],
  "nextFileId": null
}

Code

import Foundation

let apiUrl = "" // Provided by b2_authorize_account
let accountAuthorizationToken = "" // Provided by b2_authorize_account
let bucketId = "" // Provided by b2_create_bucket or b2_list_buckets

// Create the request
var request = URLRequest(url: URL(string: "\(apiUrl)/b2api/v2/b2_list_unfinished_large_files")!)
request.httpMethod = "POST"
request.addValue(accountAuthorizationToken, forHTTPHeaderField: "Authorization")
request.httpBody = "{\"bucketId\":\"\(bucketId)\"}".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

{
  "files": [
    {
      "accountId": "ACCOUNT_ID",
      "action": "start",
      "bucketId": "b2f6f21365e1d29f6c580f18",
      "contentLength": 0,
      "contentSha1": "none",
      "contentType": "application/zip",
      "fileId": "4_zb2f6f21365e1d29f6c580f18_f20150c1fda5f4c8d_d20180919_m215912_c002_v0001110_t0050",
      "fileInfo": {},
      "fileName": "~/Downloads/512MB.zip",
      "fileRetention": {
        "isClientAuthorizedToRead": true,
        "value": {
          "mode": null,
          "retainUntilTimestamp": null
        }
      },
      "legalHold": {
        "isClientAuthorizedToRead": true,
        "value": null
      },
      "serverSideEncryption": {
        "algorithm": null,
        "mode": null
      },
      "uploadTimestamp": 1537394352000
    }
  ],
  "nextFileId": null
}

Code

require 'json'
require 'net/http'
require 'digest/sha1'

api_url = "" # Provided by b2_authorize_account
account_authorization_token = "" # Provided by b2_authorize_account
bucket_id = "" # Provided by b2_create_bucket or b2_list_buckets

uri = URI.join("#{api_url}/b2api/v2/b2_list_unfinished_large_files")
req = Net::HTTP::Post.new(uri)
req.add_field("Authorization","#{account_authorization_token}")
req.body = "{\"bucketId\":\"#{bucket_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

{
  "files": [
    {
      "accountId": "ACCOUNT_ID",
      "action": "start",
      "bucketId": "b2f6f21365e1d29f6c580f18",
      "contentLength": 0,
      "contentSha1": "none",
      "contentType": "application/zip",
      "fileId": "4_zb2f6f21365e1d29f6c580f18_f20150c1fda5f4c8d_d20180919_m215912_c002_v0001110_t0050",
      "fileInfo": {},
      "fileName": "~/Downloads/512MB.zip",
      "fileRetention": {
        "isClientAuthorizedToRead": true,
        "value": {
          "mode": null,
          "retainUntilTimestamp": null
        }
      },
      "legalHold": {
        "isClientAuthorizedToRead": true,
        "value": null
      },
      "serverSideEncryption": {
        "algorithm": null,
        "mode": null
      },
      "uploadTimestamp": 1537394352000
    }
  ],
  "nextFileId": null
}

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 bucketId = ""; // Provided by b2_create_bucket or b2_list_buckets

// Get Upload URL
String getUploadUrlJsonStr = "{\"bucketId\":\"" + butcketId + "\"}";
byte[] getUloadUrlJsonData = Encoding.UTF8.GetBytes(getUploadUrlJsonStr);
HttpWebRequest getUploadUrlRequest = (HttpWebRequest)WebRequest.Create(apiUrl + "/b2api/v2/b2_list_unfinished_large_files");
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

{
  "files": [
    {
      "accountId": "ACCOUNT_ID",
      "action": "start",
      "bucketId": "b2f6f21365e1d29f6c580f18",
      "contentLength": 0,
      "contentSha1": "none",
      "contentType": "application/zip",
      "fileId": "4_zb2f6f21365e1d29f6c580f18_f20150c1fda5f4c8d_d20180919_m215912_c002_v0001110_t0050",
      "fileInfo": {},
      "fileName": "~/Downloads/512MB.zip",
      "fileRetention": {
        "isClientAuthorizedToRead": true,
        "value": {
          "mode": null,
          "retainUntilTimestamp": null
        }
      },
      "legalHold": {
        "isClientAuthorizedToRead": true,
        "value": null
      },
      "serverSideEncryption": {
        "algorithm": null,
        "mode": null
      },
      "uploadTimestamp": 1537394352000
    }
  ],
  "nextFileId": null
}

Code

<?php

$api_url = ""; // Provided by b2_authorize_account
$account_auth_token = ""; // Provided by b2_authorize_account
$bucket_id = ""; // Provided by b2_create_bucket or b2_list_buckets

// Construct post info
$data = array("bucketId" => $bucket_id);
$post_fields = json_encode($data);
$session = curl_init($api_url . "/b2api/v2/b2_list_unfinished_large_files");
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_HTTPPOST, true);  // HTTP POST
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Receive server response
$server_output = curl_exec($session);
curl_close ($session);
print $server_output;

?>

Output

{
  "files": [
    {
      "accountId": "ACCOUNT_ID",
      "action": "start",
      "bucketId": "b2f6f21365e1d29f6c580f18",
      "contentLength": 0,
      "contentSha1": "none",
      "contentType": "application/zip",
      "fileId": "4_zb2f6f21365e1d29f6c580f18_f20150c1fda5f4c8d_d20180919_m215912_c002_v0001110_t0050",
      "fileInfo": {},
      "fileName": "~/Downloads/512MB.zip",
      "fileRetention": {
        "isClientAuthorizedToRead": true,
        "value": {
          "mode": null,
          "retainUntilTimestamp": null
        }
      },
      "legalHold": {
        "isClientAuthorizedToRead": true,
        "value": null
      },
      "serverSideEncryption": {
        "algorithm": null,
        "mode": null
      },
      "uploadTimestamp": 1537394352000
    }
  ],
  "nextFileId": null
}