PHP code example of flaircore / backblaze

1. Go to this page and download the library: Download flaircore/backblaze library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

flaircore / backblaze example snippets


// Autoload dependencies installed via composer .


$b2_configs = [
    'B2_REGION' => B2_REGION,
    'B2_API_KEY' => B2_API_KEY,
    'B2_API_SECRET' => B2_API_SECRET,
    'B2_BUCKET_NAME' => B2_BUCKET_NAME,
    'B2_BUCKET_ID' => B2_BUCKET_ID,
    'B2_ENDPOINT' => B2_ENDPOINT
];


$this->b2Client = new BackblazeClient($b2_configs);


// Steps

// Authorize requests

// Get the upload url + the authorizationToken

// Upload the file (b2_upload_file)

$b2_auth = $this->b2Client->b2AuthorizeAccount();

// Required from b2_auth

$auth_token = $b2_auth->authorizationToken;

$api_url = $b2_auth->apiUrl;


$file_name = '51863901_1591128994364639_5533062884642328214_n.jpg';

$key = 'a-file-folder/'. $file_name;
// Assuming your files are stored in the '/uploads/', change to fit your folders.

$local_file = dirname(__DIR__, 1) . '/uploads/'. $file_name;


$upload_details = $this->b2Client->b2GetUploadUrl($api_url, $auth_token);

$upload_file = $this->b2Client->b2UploadFile($key, $local_file, $upload_details->uploadUrl, $upload_details->authorizationToken);

var_dump($upload_details);

var_dump($upload_file);

die('HERE TOO');

// Steps
//
//
//
$b2_auth = $this->b2Client->b2AuthorizeAccount();
// Required from b2_auth
$auth_token = $b2_auth->authorizationToken;
$api_url = $b2_auth->apiUrl;

$file_name = 'BULLET TRAIN - Official Trailer (HD).mp4';
$key = 'a-folder/'. $file_name;
// Assuming your files are stored in the '/uploads/', change to fit your folders.
$local_file = dirname(__DIR__, 1) . '/uploads/'. $file_name;

$start_upload_file = $this->b2Client->b2StartLargeFile($api_url, $auth_token, $key);
$fileId = $start_upload_file->fileId// From here, you can save the values