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.

Request HTTP Message Body Parameters

bucketId

required

The bucket to look for file names in.

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:

fileId

The unique file ID for this unfinished large file. Used with b2_upload_part, b2_finish_large_file, and b2_cancel_large_file.

fileName

The name of this file.

accountId

Your account ID.

bucketId

The bucket that the file will be in.

contentType

The MIME type of the file.

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.

uploadTimestamp

This is a UTC time when this file was started. 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 bucketId: <bucketId>

400

bad_request

Invalid startFileId: <startFileId>

400

bad_request

maxFileCount must be in the range 1 - 100

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

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/v1/b2_list_unfinished_large_files"

Output

start: {
  "files": [
    {
      "accountId": "7eecc42b9675",
      "bucketId": "e73ede9c9c8412db49f60715",
      "contentType": "application/octet-stream",
      "fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
      "fileInfo": {},
      "fileName": "bigfile.dat",
      "uploadTimestamp": 1462212184000
    }
  ],
  "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/v1/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

start: {
  "files": [
    {
      "accountId": "7eecc42b9675",
      "bucketId": "e73ede9c9c8412db49f60715",
      "contentType": "application/octet-stream",
      "fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
      "fileInfo": {},
      "fileName": "bigfile.dat",
      "uploadTimestamp": 1462212184000
    }
  ],
  "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/v1/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

account ID:  7eecc42b9675
bucket ID:  e73ede9c9c8412db49f60715
content type:  application/octet-stream
file ID:  4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001
file info:  {}
file name:  bigfile_ruby.dat
upload timestamp:  1462212184000

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
let session = NSURLSession.sharedSession()
let request = NSMutableURLRequest(URL:NSURL(string: "\(apiUrl)")!.URLByAppendingPathComponent("/b2api/v1/b2_list_unfinished_large_files"))
request.HTTPMethod = "POST"
request.addValue(accountAuthorizationToken, forHTTPHeaderField: "Authorization")
request.HTTPBody = "{\"bucketId\":\"\(bucketId)\"}".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: {
  "files": [
    {
      "accountId": "7eecc42b9675",
      "bucketId": "e73ede9c9c8412db49f60715",
      "contentType": "application/octet-stream",
      "fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
      "fileInfo": {},
      "fileName": "bigfile.dat",
      "uploadTimestamp": 1462212184000
    }
  ],
  "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/v1/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

start: {
  "files": [
    {
      "accountId": "7eecc42b9675",
      "bucketId": "e73ede9c9c8412db49f60715",
      "contentType": "application/octet-stream",
      "fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
      "fileInfo": {},
      "fileName": "bigfile.dat",
      "uploadTimestamp": 1462212184000
    }
  ],
  "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/v1/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

start: {
  "files": [
    {
      "accountId": "7eecc42b9675",
      "bucketId": "e73ede9c9c8412db49f60715",
      "contentType": "application/octet-stream",
      "fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
      "fileInfo": {},
      "fileName": "bigfile.dat",
      "uploadTimestamp": 1462212184000
    }
  ],
  "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/v1/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

start: {
  "files": [
    {
      "accountId": "7eecc42b9675",
      "bucketId": "e73ede9c9c8412db49f60715",
      "contentType": "application/octet-stream",
      "fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
      "fileInfo": {},
      "fileName": "bigfile.dat",
      "uploadTimestamp": 1462212184000
    }
  ],
  "nextFileId": null
}