#Backblaze B2 API Wrapper by Dan Rovito This is a PHP wrapper for the Backblaze B2 API.
This wrapper is in active development.
##From the B2 Website
B2 Cloud Storage is a cloud service for storing files in the cloud. Files are available for download at any time, either through the API or through a browser-compatible URL.
##Usage
All responses are JSON
Add to your composer.json
"danrovito/backblaze-b2-api-wrapper": "dev-master"##Below you'll find more information on how to carry out the specific functions of the API wrapper.
###Authorization
You'll need to authorize your B2 account to retrieve certain information to use in later API calls. The response body will contain the following:
- acccountId
- authorizationToken
- apiUrl
- downloadUrl
####Sample code You need to pass your Account ID and Application key from your B2 account to get your authorization response. To call the authorization function do the following:
use b2_api;
$b2 = new b2_api;
$response = $b2->b2_authorize_account("ACCOUNTID", "APPLICATIONKEY");
return $response;You will receive a response similar to the following:
{
"accountId": "YOUR_ACCOUNT_ID",
"apiUrl": "https://api900.backblaze.com",
"authorizationToken": "2_20150807002553_443e98bf57f978fa58c284f8_24d25d99772e3ba927778b39c9b0198f412d2163_acct",
"downloadUrl": "https://f900.backblaze.com",
"minimumPartSize": 100000000
}The Authorization Token will change everytime this function is used.
###Create a Bucket
####Sample Code
You can pass all the information you need to create a bucket by using this code
BUCKETTYPE can be "allPrivate" or "allPublic"
$new_bucket = $b2->b2_create_bucket('YOURBUCKETNAME', 'BUCKETTYPE');You will receive a response similar to the following:
{
"bucketId" : "4a48fe8875c6214145260818",
"accountId" : "010203040506",
"bucketName" : "any_name_you_pick",
"bucketType" : "allPrivate"
}If the bucket name is in use by anyone else you will receive a response similar to this:
{
"code": "duplicate_bucket_name",
"message": "Bucket name is already in use.",
"status": 400
}###Delete a Bucket
####Sample Code
Just pass in the bucket ID that you want to delete and it will remove it from your B2 account.
$delete = $b2->b2_delete_bucket('BUCKETID');You will receive a response similar to the following:
{
"bucketId" : "4a48fe8875c6214145260818",
"accountId" : "010203040506",
"bucketName" : "any_name_you_pick",
"bucketType" : "allPrivate"
}###Delete File by Version
####Sample Code
Pass the file ID and Name to delete the file.
$deleteFile = $b2->b2_delete_file_version('FILEID', 'FILENAME');You will receive a response similar to the following:
{
"fileId" : "4_h4a48fe8875c6214145260818_f000000000000472a_d20140104_m032022_c001_v0000123_t0104",
"fileName" : "test.txt"
}###Delete File by Name
####Sample Code
Pass the bucket name and file name to receive the file.
$file = $b2->b2_download_file_by_name('BUCKETNAME', 'FILENAME');You will receive a response similar to the following:
The output is the file that you asked for.
###Download File by ID
####Sample Code
Pass the file ID to receive the file.
$file = $b2->b2_download_file_by_id('FILEID');The output is the file that you asked for.
###Get upload URL
####Sample Code
Pass the bucket ID to receive the upload url.
$uploadUrl = $b2->b2_get_upload_url('BUCKETID');You will receive a response similar to the following:
{
"bucketId" : "4a48fe8875c6214145260818",
"uploadUrl" : "https://pod-000-1005-03.backblaze.com/b2api/v1/b2_upload_file?cvt=c001_v0001005_t0027&bucket=4a48fe8875c6214145260818",
"authorizationToken" : "2_20151009170037_f504a0f39a0f4e657337e624_9754dde94359bd7b8f1445c8f4cc1a231a33f714_upld"
}