b2_hide_file

Hides a file so that downloading by name will not find the file, but previous versions of the file are still stored. See File Versions about what it means to hide a file.

Request

Request HTTP Headers

Authorization

required

An authorization token, obtained from b2_authorize_account. The token must have the writeFiles capability.

Request HTTP Message Body Parameters

bucketId

required

The bucket containing the file to hide.

fileName

required

The name of the file to hide.

Response

Response HTTP Status 200

File successfully hidden. The JSON response will contain the standard file structure, and the action will be "hide".

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

Unable to hide file. 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.

404

not_found

File is not in B2 Cloud Storage.

API Versions

v2: Consistent file structures (Sept 13, 2018)

Now returns accountId and bucketId. Does not return size any more; use contentLength instead.

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

curl \
    -H 'Authorization: ACCOUNT_AUTHORIZATION_TOKEN' \
    -d '{"bucketId": "BUCKET_ID", "fileName": "FILE_NAME"}' \
    https://apiNNN.backblazeb2.com/b2api/v2/b2_hide_file

Output

{
  "accountId": "ACCOUNT_ID",
  "action": "hide",
  "bucketId": "BUCKET_ID",
  "contentLength": 0,
  "contentSha1": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
  "contentType": "application/x-bz-hide-marker",
  "fileId": "4_zb2f6f21365e1d29f6c580f18_f10305b68895d22f4_d20180914_m221207_c002_v0001108_t0029",
  "fileInfo": {},
  "fileName": "FILE_NAME",
  "fileRetention": {
    "isClientAuthorizedToRead": true,
    "value": {
      "mode": null,
      "retainUntilTimestamp": null
    }
  },
  "legalHold": {
    "isClientAuthorizedToRead": true,
    "value": null
  },
  "serverSideEncryption": {
    "algorithm": null,
    "mode": null
  },
  "size": 0,
  "uploadTimestamp": 1536963127000
}

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 accountAuthorizationToken = ""; // Provided by b2_authorize_account
String fileName = ""; // The file name of the file you want to hide.
String bucketId = ""; // The ID of bucket where the file you want to hide resides.
HttpURLConnection connection = null;
String postParams = "{\"bucketId\":\"" + bucketId + "\",\"fileName\":\"" + fileName + "\"}";
byte postData[] = postParams.getBytes(StandardCharsets.UTF_8);
try {
    URL url = new URL(apiUrl + "/b2api/v2/b2_hide_file");
    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": "ACCOUNT_ID",
  "action": "hide",
  "bucketId": "BUCKET_ID",
  "contentLength": 0,
  "contentSha1": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
  "contentType": "application/x-bz-hide-marker",
  "fileId": "4_zb2f6f21365e1d29f6c580f18_f10305b68895d22f4_d20180914_m221207_c002_v0001108_t0029",
  "fileInfo": {},
  "fileName": "FILE_NAME",
  "fileRetention": {
    "isClientAuthorizedToRead": true,
    "value": {
      "mode": null,
      "retainUntilTimestamp": null
    }
  },
  "legalHold": {
    "isClientAuthorizedToRead": true,
    "value": null
  },
  "serverSideEncryption": {
    "algorithm": null,
    "mode": null
  },
  "size": 0,
  "uploadTimestamp": 1536963127000
}

Code

import json
import urllib2

api_url = "" # Provided by b2_authorize_account
account_authorization_token = "" # Provided by b2_authorize_account
file_name = "" # The file name of the file you want to hide.
bucket_id = "" # The ID of bucket where the file you want to hide resides.
request = urllib2.Request(
	'%s/b2api/v2/b2_hide_file' % api_url,
	json.dumps({ 'bucketId' : bucket_id , 'fileName' : file_name }),
	headers = { 'Authorization': account_authorization_token }
	)
response = urllib2.urlopen(request)
response_data = json.loads(response.read())
response.close()

Output

{
    "accountId": "ACCOUNT_ID",
    "action": "hide",
    "bucketId": "BUCKET_ID",
    "contentLength": 0,
    "contentSha1": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
    "contentType": "application/x-bz-hide-marker",
    "fileId": "4_zb2f6f21365e1d29f6c580f18_f10305b68895d22f4_d20180914_m221207_c002_v0001108_t0029",
    "fileInfo": {},
    "fileName": "FILE_NAME",
    "fileRetention": {
      "isClientAuthorizedToRead": true,
      "value": {
        "mode": null,
        "retainUntilTimestamp": null
      }
    },
    "legalHold": {
      "isClientAuthorizedToRead": true,
      "value": null
    },
    "serverSideEncryption": {
      "algorithm": null,
      "mode": null
    },
    "size": 0,
    "uploadTimestamp": 1536963127000
}

Code

import Foundation

let apiUrl = "" // Provided by b2_authorize_account
let accountAuthorizationToken = "" // Provided by b2_authorize_account
let fileName = "" // The file name of the file you want to hide.
let bucketId = "" // The ID of bucket where the file you want to hide resides.

// Create the request
var request = URLRequest(url: URL(string: "\(apiUrl)/b2api/v2/b2_hide_file")!)
request.httpMethod = "POST"
request.addValue(accountAuthorizationToken, forHTTPHeaderField: "Authorization")
request.httpBody = "{\"fileName\":\"\(fileName)\",\"bucketId\":\"\(bucketId)\"}".data(using: .utf8)

// Create the task
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
	if let data = data {
		let json = String(data: data, 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

{
  "accountId": "ACCOUNT_ID",
  "action": "hide",
  "bucketId": "BUCKET_ID",
  "contentLength": 0,
  "contentSha1": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
  "contentType": "application/x-bz-hide-marker",
  "fileId": "4_zb2f6f21365e1d29f6c580f18_f10305b68895d22f4_d20180914_m221207_c002_v0001108_t0029",
  "fileInfo": {},
  "fileName": "FILE_NAME",
  "fileRetention": {
    "isClientAuthorizedToRead": true,
    "value": {
      "mode": null,
      "retainUntilTimestamp": null
    }
  },
  "legalHold": {
    "isClientAuthorizedToRead": true,
    "value": null
  },
  "serverSideEncryption": {
    "algorithm": null,
    "mode": null
  },
  "size": 0,
  "uploadTimestamp": 1536963127000
}

Code

require 'json'
require 'net/http'

api_url = "" # Provided by b2_authorize_account
account_authorization_token = "" # Provided by b2_authorize_account
file_name = "" # The file name of the file you want to hide.
bucket_id = "" # The ID of bucket where the file you want to hide resides.
uri = URI("#{api_url}/b2api/v2/b2_hide_file")
req = Net::HTTP::Post.new(uri)
req.add_field("Authorization","#{account_authorization_token}")
req.body = "{\"fileName\":\"\(file_name)\", \"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
    res.body
when Net::HTTPRedirection then
    fetch(res['location'], limit - 1)
else
    res.error!
end

Output

{
  "accountId": "ACCOUNT_ID",
  "action": "hide",
  "bucketId": "BUCKET_ID",
  "contentLength": 0,
  "contentSha1": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
  "contentType": "application/x-bz-hide-marker",
  "fileId": "4_zb2f6f21365e1d29f6c580f18_f10305b68895d22f4_d20180914_m221207_c002_v0001108_t0029",
  "fileInfo": {},
  "fileName": "FILE_NAME",
  "fileRetention": {
    "isClientAuthorizedToRead": true,
    "value": {
      "mode": null,
      "retainUntilTimestamp": null
    }
  },
  "legalHold": {
    "isClientAuthorizedToRead": true,
    "value": null
  },
  "serverSideEncryption": {
    "algorithm": null,
    "mode": null
  },
  "size": 0,
  "uploadTimestamp": 1536963127000
}

Code

String apiUrl = "API_URL"; //Provided by b2_authorize_account
String accountAuthorizationToken = "ACCOUNT_AUTHORIZATION_TOKEN"; //Provided by b2_authorize_account
String bucketId = "BUCKET_ID"; //The unique bucket ID
String bucketName = "BUCKET_NAME"; //The unique bucket name
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(apiUrl + "/b2api/v2/b2_hide_file");
string body =
"{\"bucketId\":\"" + bucketId + "\",\n" +
"\"bucketName\":\"" + bucketName + "\"}";
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": "ACCOUNT_ID",
  "action": "hide",
  "bucketId": "BUCKET_ID",
  "contentLength": 0,
  "contentSha1": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
  "contentType": "application/x-bz-hide-marker",
  "fileId": "4_zb2f6f21365e1d29f6c580f18_f10305b68895d22f4_d20180914_m221207_c002_v0001108_t0029",
  "fileInfo": {},
  "fileName": "FILE_NAME",
  "fileRetention": {
    "isClientAuthorizedToRead": true,
    "value": {
      "mode": null,
      "retainUntilTimestamp": null
    }
  },
  "legalHold": {
    "isClientAuthorizedToRead": true,
    "value": null
  },
  "serverSideEncryption": {
    "algorithm": null,
    "mode": null
  },
  "size": 0,
  "uploadTimestamp": 1536963127000
}

Code

$api_url = ""; // From b2_authorize_account call
$auth_token = ""; // From b2_authorize_account call
$bucket_id = "";  // The ID of the bucket
$file_name = "file.txt"; // The file name of the file you want to hide

$session = curl_init($api_url .  "/b2api/v2/b2_hide_file");

// Add post fields
$data = array("bucketId" => $bucket_id, "fileName" => $file_name);
$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": "ACCOUNT_ID",
    "action": "hide",
    "bucketId": "BUCKET_ID",
    "contentLength": 0,
    "contentSha1": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
    "contentType": "application/x-bz-hide-marker",
    "fileId": "4_zb2f6f21365e1d29f6c580f18_f10305b68895d22f4_d20180914_m221207_c002_v0001108_t0029",
    "fileInfo": {},
    "fileName": "FILE_NAME",
    "fileRetention": {
      "isClientAuthorizedToRead": true,
      "value": {
        "mode": null,
        "retainUntilTimestamp": null
      }
    },
    "legalHold": {
      "isClientAuthorizedToRead": true,
      "value": null
    },
    "serverSideEncryption": {
      "algorithm": null,
      "mode": null
    },
    "size": 0,
    "uploadTimestamp": 1536963127000
}