Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
![Total Downloads](https://img.shields.io/packagist/dt/utopia-php/storage.svg)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord)](https://appwrite.io/discord)

Utopia Storage library is simple and lite library for managing application storage. It supports multiple storage adapters. We already support AWS S3 storage, Digitalocean Spaces storage and Linode Object storage. This library is aiming to be as simple and easy to learn and use. This library is maintained by the [Appwrite team](https://appwrite.io).
Utopia Storage library is simple and lite library for managing application storage. It supports multiple storage adapters. We already support AWS S3 storage, Digitalocean Spaces storage, Backblaze B2 Cloud storage, Linode Object storage and Wasabi Cloud storage. This library is aiming to be as simple and easy to learn and use. This library is maintained by the [Appwrite team](https://appwrite.io).

This library is part of the [Utopia Framework](https://github.com/utopia-php/framework) project.

Expand Down
58 changes: 33 additions & 25 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions src/Storage/Device/BackBlaze.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Utopia\Storage\Device;

use Utopia\Storage\Device\S3;

class BackBlaze extends S3
{
/**
* Regions constants
*
*/
const US_WEST_001 = 'us-west-001';
const US_WEST_002 = 'us-west-002';
const US_WEST_003 = 'us-west-003';
const US_WEST_004 = 'us-west-004';
const EU_CENTRAL_001 = 'eu-central-001';
const EU_CENTRAL_002 = 'eu-central-002';
const EU_CENTRAL_003 = 'eu-central-003';
const EU_CENTRAL_004 = 'eu-central-004';

/**
* BackBlaze Constructor
*
* @param string $root
* @param string $accessKey
* @param string $secretKey
* @param string $bucket
* @param string $region
* @param string $acl
*/
public function __construct(string $root, string $accessKey, string $secretKey, string $bucket, string $region = self::US_WEST_004, string $acl = self::ACL_PRIVATE)
{
parent::__construct($root, $accessKey, $secretKey, $bucket, $region, $acl);
$this->headers['host'] = $bucket . '.' . 's3' . '.' . $region . '.backblazeb2.com';
}

/**
* @return string
*/
public function getName(): string
{
return 'BackBlaze B2 Storage';
}

/**
* @return string
*/
public function getDescription(): string
{
return 'BackBlaze B2 Storage';
}
}
5 changes: 3 additions & 2 deletions src/Storage/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Storage
const DEVICE_LOCAL = 'Local';
const DEVICE_S3 = 'S3';
const DEVICE_DO_SPACES = 'DOSpaces';
const DEVICE_LINODE='Linode';
const DEVICE_BACKBLAZE = 'BackBlaze';
const DEVICE_LINODE= 'Linode';

/**
* Devices.
Expand Down Expand Up @@ -119,4 +120,4 @@ public static function human(int $bytes, $decimals = 2, $system = 'metric')

return sprintf("%.{$decimals}f%s", $bytes / pow($mod, $factor), $units[$system][$factor]);
}
}
}
30 changes: 30 additions & 0 deletions tests/Storage/Device/BackBlazeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Utopia\Tests;

use Utopia\Storage\Device\BackBlaze;
use Utopia\Tests\S3Base;

class BackBlazeTest extends S3Base
{
protected function init(): void
{
$this->root = 'root';
$key = $_SERVER['BACKBLAZE_ACCESS_KEY'] ?? '';
$secret = $_SERVER['BACKBLAZE_SECRET'] ?? '';
$bucket = "backblaze-demo";

$this->object = new BackBlaze($this->root, $key, $secret, $bucket, BackBlaze::US_WEST_004, BackBlaze::ACL_PRIVATE);

}

protected function getAdapterName(): string
{
return 'BackBlaze B2 Storage';
}

protected function getAdapterDescription(): string
{
return 'BackBlaze B2 Storage';
}
}