b2_get_file_info

Gets information about one file stored in B2.

This will return an error if called on a non-existent file ID or if called on an unfinished large file.

Request

Request HTTP Headers

Authorization

required

The account authorization token returned by b2_authorize_account.

Request HTTP Message Body Parameters

fileId

required

The ID of the file, as returned by b2_upload_file, b2_hide_file, b2_list_file_names, or b2_list_file_versions.

Response

Response HTTP Status 200

File info returned as a JSON response:

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.

fileName

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

accountId

Your account ID.

contentSha1

The Sha1 hash of the contents of the file stored in B2.

bucketId

The bucket that the file is in.

contentLength

The number of bytes stored in the file.

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. There are two recommended names inside this JSON object (but feel free to add more): src_last_modified_millis as one of the names and for large files large_file_sha1 as one of the names. The format of these values is specified in b2_upload_file and b2_start_large_file.

action

One of "upload", or "hide". "upload" means a file that was uploaded to B2 Cloud Storage. "hide" means a file version marking the file as hidden, so that it will not show up in b2_list_file_names.

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).

Response Errors

If possible the server will return a JSON error structure. Errors include:

status

code

message

400

bad_request

No Authorization header

401

unauthorized

Not authorized

404

not_found

file_state_deleted

404

not_found

file_state_none

404

not_found

file_state_unknown

Sample Code

Code

FILE_ID=... # The ID of the file you want to get info on 
ACCOUNT_AUTHORIZATION_TOKEN = "" # Provided by b2_authorize_account

curl -H 'Authorization: $ACCOUNT_AUTHORIZATION_TOKEN' \
     -D '{"fileId":"$FILE_ID"}' \
     https://apiNNN.backblazeb2.com/b2api/v1/b2_get_file_info

Output

{
    "accountId": "7eecc42b9675",
    "bucketId": "e73ede9c9c8412db49f60715",
    "contentLength": 122573,
    "contentSha1": "a01a21253a07fb08a354acd30f3a6f32abb76821",
    "contentType": "image/jpeg",
    "fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
    "fileInfo": {},
    "fileName": "akitty.jpg"
}

Code

import java.io.*;
import java.util.*;
import javax.json.*;
import java.net.HttpURLConnection;
import java.net.URL;

String apiUrl = ""; // Provided by b2_authorize_account
String fileId = ""; // The ID of the file you want to get info on 
String accountAuthorizationToken = ""; // Provided by b2_authorize_account
HttpURLConnection connection = null;
String postParams = "{\"fileId\":\"" + fileId + "\"}";
byte postData[] = postParams.getBytes(StandardCharsets.UTF_8);
try {
    URL url = new URL(apiUrl + "/b2api/v1/b2_get_file_info");
    connection = (HttpURLConnection)url.openConnection();
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Authorization", accountAuthorizationToken);
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    connection.setRequestProperty("charset", "utf-8");
    connection.setRequestProperty("Content-Length", Integer.toString(postData.length));
    connection.setDoOutput(true);
    DataOutputStream writer = new DataOutputStream(connection.getOutputStream());
    writer.write(postData);
    String jsonResponse = myInputStreamReader(connection.getInputStream());
    System.out.println(jsonResponse);
} catch (Exception e) {
    e.printStackTrace();
} finally {
    connection.disconnect();
}

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

{
    "accountId": "7eecc42b9675",
    "bucketId": "e73ede9c9c8412db49f60715",
    "contentLength": 122573,
    "contentSha1": "a01a21253a07fb08a354acd30f3a6f32abb76821",
    "contentType": "image/jpeg",
    "fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
    "fileInfo": {},
    "fileName": "akitty.jpg"
}

Code

import json
import urllib2

api_url = "" # Provided by b2_authorize_account
file_id = "" # The ID of the file you want to get info on 
account_authorization_token = "" # Provided by b2_authorize_account
request = urllib2.Request(
    '%s/b2api/v1/b2_get_file_info' % 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

{
    "accountId": "7eecc42b9675",
    "bucketId": "e73ede9c9c8412db49f60715",
    "contentLength": 122573,
    "contentSha1": "a01a21253a07fb08a354acd30f3a6f32abb76821",
    "contentType": "image/jpeg",
    "fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
    "fileInfo": {},
    "fileName": "akitty.jpg"
}

Code

import Foundation

let apiUrl = "" // Provided by b2_authorize_account
let fileId = "" // The ID of the file you want to get info on 
let accountAuthorizationToken = "" // Provided by b2_authorize_account
let session = NSURLSession.sharedSession()
let request = NSMutableURLRequest(URL:NSURL(string: "\(apiUrl)")!.URLByAppendingPathComponent("/b2api/v1/b2_get_file_info"))
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 data != nil {
        let json = NSString(data: data, encoding:NSUTF8StringEncoding)
    }
})
task.resume()

Output

{
    "accountId": "7eecc42b9675",
    "bucketId": "e73ede9c9c8412db49f60715",
    "contentLength": 122573,
    "contentSha1": "a01a21253a07fb08a354acd30f3a6f32abb76821",
    "contentType": "image/jpeg",
    "fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
    "fileInfo": {},
    "fileName": "akitty.jpg"
}

Code

require 'json'
require 'net/http'

api_url = "" # Provided by b2_authorize_account
file_id = "" # The ID of the file you want to get info on 
account_authorization_token = "" # Provided by b2_authorize_account
uri = URI.join("#{api_url}/b2api/v1/b2_get_file_info")
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
    res.body
when Net::HTTPRedirection then
    fetch(res['location'], limit - 1)
else
    res.error!
end

Output

{
    "accountId": "7eecc42b9675",
    "bucketId": "e73ede9c9c8412db49f60715",
    "contentLength": 122573,
    "contentSha1": "a01a21253a07fb08a354acd30f3a6f32abb76821",
    "contentType": "image/jpeg",
    "fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
    "fileInfo": {},
    "fileName": "akitty.jpg"
}

Code

String apiUrl = "API_URL"; //Provided by b2_authorize_account 
String accountAuthorizationToken = "ACCOUNT_AUTHORIZATION_TOKEN"; //Provided by b2_authorize_account 
String fileId = "FILE_ID"; //The unique file ID
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(apiUrl + "/b2api/v1/b2_get_file_info");
string body = "{\"fileId\":\"" + fileId + "\"}";
var data = Encoding.UTF8.GetBytes(body);
webRequest.Method = "POST";
webRequest.Headers.Add("Authorization", accountAuthorizationToken);
webRequest.ContentType = "application/json; charset=utf-8";
webRequest.ContentLength = data.Length;
using (var stream = webRequest.GetRequestStream())
{
stream.Write(data, 0, data.Length);
stream.Close();
}
WebResponse response = (HttpWebResponse)webRequest.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
response.Close();
Console.WriteLine(responseString);

Output

{
    "accountId": "7eecc42b9675",
    "bucketId": "e73ede9c9c8412db49f60715",
    "contentLength": 122573,
    "contentSha1": "a01a21253a07fb08a354acd30f3a6f32abb76821",
    "contentType": "image/jpeg",
    "fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
    "fileInfo": {},
    "fileName": "akitty.jpg"
}

Code

$api_url = ""; // From b2_authorize_account call
$auth_token = ""; // From b2_authorize_account call
$file_id = ""; // The id of the file
$session = curl_init($api_url .  "/b2api/v1/b2_get_file_info");

// Add post fields
$data = array("fileId" => $file_id);
$post_fields = json_encode($data);
curl_setopt($session, CURLOPT_POSTFIELDS, $post_fields); 

// Add headers
$headers = array();
$headers[] = "Authorization: " . $auth_token;
curl_setopt($session, CURLOPT_HTTPHEADER, $headers); 

curl_setopt($session, CURLOPT_POST, true); // HTTP POST
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);  // Receive server response
$server_output = curl_exec($session); // Let's do this!
curl_close ($session); // Clean up
echo ($server_output); // Tell me about the rabbits, George!

Output

{
    "accountId": "7eecc42b9675",
    "bucketId": "e73ede9c9c8412db49f60715",
    "contentLength": 122573,
    "contentSha1": "a01a21253a07fb08a354acd30f3a6f32abb76821",
    "contentType": "image/jpeg",
    "fileId": "4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001",
    "fileInfo": {},
    "fileName": "akitty.jpg"
}