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.

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:

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.

contentLength

Always 0. The version that hides the file takes no storage.

contentType

Always null.

contentSha1

Always null.

fileInfo

Always an empty JSON object.

action

Always "hide".

size

Deprecated. Same as contentLength.

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

Unable to hide file. If possible the server will return a JSON error structure. Errors include:

status

code

message

400

bad_request

Invalid bucket id: <bucketId>

400

bad_bucket_id

bucket <bucketId> does not exist

400

bad_request

Snapshot buckets are reserved for Backblaze use

400

bad_request

Allow snapshot header must be specified when hiding a file for snapshot bucket

400

no_such_file

File not present: <fileName>

400

already_hidden

File already hidden: <fileName>

400

bad_request

File names must contain at least one character

400

bad_request

File names in UTF8 must be no more than 1000 bytes

400

bad_request

File names must not start with '/'

400

bad_request

File names must not end with '/'

400

bad_request

File names must not contain '\'

400

bad_request

File names must not contain DELETE

400

bad_request

File names must not contain '//'

400

bad_request

File names segment must not be more than 250 bytes

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

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

Output

{
    "action" : "hide",
    "fileId" : "4_h4a48fe8875c6214145260818_f000000000000472a_d20140104_m032022_c001_v0000123_t0104",
    "fileName" : "typing_test.txt",
    "uploadTimestamp" : 1437815673000
}

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

{
    "action" : "hide",
    "fileId" : "4_h4a48fe8875c6214145260818_f000000000000472a_d20140104_m032022_c001_v0000123_t0104",
    "fileName" : "typing_test.txt",
    "uploadTimestamp" : 1437815673000
}

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

{
    "action" : "hide",
    "fileId" : "4_h4a48fe8875c6214145260818_f000000000000472a_d20140104_m032022_c001_v0000123_t0104",
    "fileName" : "typing_test.txt",
    "uploadTimestamp" : 1437815673000
}

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.
let session = NSURLSession.sharedSession()
let request = NSMutableURLRequest(URL:NSURL(string: "\(apiUrl)")!.URLByAppendingPathComponent("/b2api/v1/b2_hide_file"))
request.HTTPMethod = "POST"
request.addValue(accountAuthorizationToken, forHTTPHeaderField: "Authorization")
request.HTTPBody = "{\"fileName\":\"\(fileName)\",\"bucketId\":\"\(bucketId)\"}".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

{
    "action" : "hide",
    "fileId" : "4_h4a48fe8875c6214145260818_f000000000000472a_d20140104_m032022_c001_v0000123_t0104",
    "fileName" : "typing_test.txt",
    "uploadTimestamp" : 1437815673000
}

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

{
    "action" : "hide",
    "fileId" : "4_h4a48fe8875c6214145260818_f000000000000472a_d20140104_m032022_c001_v0000123_t0104",
    "fileName" : "typing_test.txt",
    "uploadTimestamp" : 1437815673000
}

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

{
    "action" : "hide",
    "fileId" : "4_h4a48fe8875c6214145260818_f000000000000472a_d20140104_m032022_c001_v0000123_t0104",
    "fileName" : "typing_test.txt",
    "uploadTimestamp" : 1437815673000
}

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

{
    "action" : "hide",
    "fileId" : "4_h4a48fe8875c6214145260818_f000000000000472a_d20140104_m032022_c001_v0000123_t0104",
    "fileName" : "typing_test.txt",
    "uploadTimestamp" : 1437815673000
}