Files

A file contains a sequence of bytes. Any file on your computer can be uploaded to B2 and stored in a Cloud Storage, as long as it's not too big. Files can range in size from 0 bytes to 5 billion bytes.

Once a file is uploaded, you can download it right away, or wait years and then download it. You can download it once, or give the URL to all of your friends and they can all download it.

Uploading the same file name more than once results in multiple versions of the same file. This can be useful for tracking the history of a document. See File Versions for more details.

The API calls related to files are:

File Names

Files have names, which are set when a file is uploaded. Once a file is uploaded, its name cannot be changed. You can then download a file if you know its name.

Names can be pretty much any UTF-8 string up to 1024 bytes long. There are a few picky rules:

  • No character codes below 32 are allowed.
  • Backslashes are not allowed.
  • DEL characters (127) are not allowed.
  • File names cannot start with "/", end with "/", or contain "//".

These are all valid file names:

  • Kitten Videos
  • users/beatrice/kitten.jpg
  • 自由.txt

To help ensure that B2 files can be easily exported to disk file systems, there is a maximum of 250 bytes of UTF-8 in each segment of a file name. A segment is the part between slashes. So while file names can be up to 1024 bytes long, a file name that long must have at least four slashes in it, with each of the parts between the slashes being 250 bytes or less.

File IDs

In addition to a name, each file uploaded has a unique ID that identifies that specific version of that file. A File ID will not be more than 200 characters. If you want to download an older version of a file, you'll need to know its File ID. File IDs look like this:

4_zb330e285948b7a6d4b1b0712_f000000000000472a_d20140104_m032022_c001_v0000123_t0104

Listing Files

You can call b2_list_file_names to get a list of the files in a bucket, and b2_list_file_versions to list all of the versions of files in a bucket. See File Versions for more details.

Downloading Files

If you have uploaded a file called cats/kitten.jpg to a bucket called cute_pictures, you'll be able to view the file in a browser with a URL that looks like this:

https://f001.backblazeb2.com/file/cute_pictures/cats/kitten.jpg

The first part of the URL comes is the download URL that you get from the b2_authorize_account call. Then comes /file/, then the bucket name, another /, and then the file name.

Folders (There Are No Folders)

A bucket holds files. There is no hierarchy of folders, just one long, flat list of file names. For example, a bucket might have four files in it, with these four names:

cats/cat.jpg
cats/kitten.jpg
dogs/dog.jpg
dogs/puppy.jpg

There are no folders. The name of the first file is cats/cat.jpg, and the name of the second file is cats/kitten.jpg. There is nothing called just cats.

Even though there are no folders, many of the tools that work with files in a bucket act like there are folders. The file browser on the Backblaze web site acts like there are folders, and so does the b2 command-line tool. Under the covers, they both just scan through the flat list of files and pretend. Here's an example of using the command-line tool:

$ b2 ls my_bucket
cats/
dogs/
$ b2 ls my_bucket cats
cat.jpg
kitten.jpg

We recommend that you use "/" to separate folder names, just like you would for files on your computer. (Or just like you would use "\" if you use Windows.) That way the tools can figure out the implied folder structure.

Checksums

To ensure the integrity of your data, when you upload a file you must provide a SHA1 checksum of the data. This ensures that if any of the data is corrupted in the network on its way to B2, it will be detected before the file is stored. When you download a file, the SHA1 checksum is attached so that you can verify that the data you receive is intact.

MIME Types

When you upload a file, you also provide a MIME type for the file, which will be used when a browser downloads the file so that it knows what kind of file it is. For example, if you say that your file kitten.jpg has a MIME type of image/jpeg, then a browser that downloads the file will know that it's an image to be displayed.

File Info

Each file has information associated with it, in addition to the sequence of bytes that the file contains. Every file has a size (the number of bytes in the file), a MIME type, and a SHA1 checksum. You can also add your own custom information.

Your custom file information can be up to 10 key/value pairs. Each key is a UTF-8 string up to 50 bytes long, and can contain letters, numbers, "-" and "_". Each key is converted to lowercase. Names that begin with "b2-" are reserved. There is an overall 7000-byte limit on the headers needed for file name and file info. (See next section.)

For names that don't start with "b2-", there is no limit on the size or content of the values, other than the overall size limit.

Names that start with "b2-" must be in the list of defined "b2-" names and their values must be valid. See the list below for details. B2 rejects any upload request with an unexpected "b2-" file info name. B2 also rejects any upload with a "b2-" file info name whose value doesn't meet the specified format for that name.

b2-content-disposition

optional

If this is present, B2 will use it as the value of the 'Content-Disposition' header when the file is downloaded (unless it's overridden by a value given in the download request). The value must match the grammar specified in RFC 6266 (except that parameter names that contain an '*' are not allowed). Note that this file info will not be included in downloads as a x-bz-info-b2-content-disposition header. Instead, it (or the value specified in a request) will be in the Content-Disposition.

You provide the File Info with the b2_upload_file call for regular files, and b2_start_large_file for large files. It is set when the file is uploaded and cannot be changed. The b2_get_file_info call returns the information about a file. The information is also returned in the HTTP headers when you download a file.

Recommended File Info key/value: If the original source of the file being uploaded has a last modified time concept, Backblaze recommends using src_last_modified_millis as the key, and for the value use a string holding the base 10 number 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).

Recommended File Info key/value: If this is a large file (meaning the caller is using b2_start_large_file) and if the caller knows the SHA1 of the entire large file being uploaded, Backblaze recommends using large_file_sha1 as the key, and for the value use a 40 byte hex string representing the SHA1.

HTTP Header Size Limit

The file name and file info must fit, along with the other necessary headers, within an 8KB limit imposed by some web servers and proxies. To ensure this, both now and in the future, B2 limits the combined header size for the file name and all file info to 7000 bytes. This limit applies to the fully encoded HTTP header line, including the carriage-return and newline. This header line is counted as 40 bytes:

    X-Bz-File-Name: %E8%87%AA%E7%94%B1.txt\r\n