gliterd / backblaze-b2 Goto Github PK
View Code? Open in Web Editor NEW:vhs: A standard PHP SDK for backblaze b2 cloud files & storage system
Home Page: https://www.backblaze.com/b2/cloud-storage.html
License: MIT License
:vhs: A standard PHP SDK for backblaze b2 cloud files & storage system
Home Page: https://www.backblaze.com/b2/cloud-storage.html
License: MIT License
Is there a way to use the $client->listFiles
function filtering by file prefix? I have a bucket with 200k files and I would need to retrieve info only on those belonging to a given directory.
Thanks, S.
The library wants me to use a version of Carbon that's outdated by an entire major release...
Angius@AngPC MINGW64 /e/Software/Laragon/www/omnibus2 (master)
$ composer require nesbot/carbon
Using version ^2.23 for nesbot/carbon
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- gliterd/backblaze-b2 1.3.0 requires nesbot/carbon ~1.20 -> satisfiable by nesbot/carbon[1.20.0, 1.21.0, 1.22.0, 1.22.1, 1.23.0, 1.24.0, 1.24.1, 1.24.2, 1.25.0, 1.25.1, 1.25.3, 1.26.0, 1.26.1, 1.26.2, 1.26.3, 1.26.4, 1.26.5, 1.26.6, 1.27.0, 1.28.0, 1.29.0, 1.29.1, 1.29.2, 1.30.0, 1.31.0, 1.31.1, 1.32.0, 1.33.0, 1.34.0, 1.34.1, 1.34.2, 1.34.3, 1.34.4, 1.35.0, 1.35.1, 1.36.0, 1.36.1, 1.36.2, 1.37.0, 1.37.1, 1.38.0, 1.38.1, 1.38.2, 1.38.3, 1.38.4, 1.39.0] but these conflict with your requirements or minimum-stability.
- gliterd/backblaze-b2 1.3.0 requires nesbot/carbon ~1.20 -> satisfiable by nesbot/carbon[1.20.0, 1.21.0, 1.22.0, 1.22.1, 1.23.0, 1.24.0, 1.24.1, 1.24.2, 1.25.0, 1.25.1, 1.25.3, 1.26.0, 1.26.1, 1.26.2, 1.26.3, 1.26.4, 1.26.5, 1.26.6, 1.27.0, 1.28.0, 1.29.0, 1.29.1, 1.29.2, 1.30.0, 1.31.0, 1.31.1, 1.32.0, 1.33.0, 1.34.0, 1.34.1, 1.34.2, 1.34.3, 1.34.4, 1.35.0, 1.35.1, 1.36.0, 1.36.1, 1.36.2, 1.37.0, 1.37.1, 1.38.0, 1.38.1, 1.38.2, 1.38.3, 1.38.4, 1.39.0] but these conflict with your requirements or minimum-stability.
- gliterd/backblaze-b2 1.3.0 requires nesbot/carbon ~1.20 -> satisfiable by nesbot/carbon[1.20.0, 1.21.0, 1.22.0, 1.22.1, 1.23.0, 1.24.0, 1.24.1, 1.24.2, 1.25.0, 1.25.1, 1.25.3, 1.26.0, 1.26.1, 1.26.2, 1.26.3, 1.26.4, 1.26.5, 1.26.6, 1.27.0, 1.28.0, 1.29.0, 1.29.1, 1.29.2, 1.30.0, 1.31.0, 1.31.1, 1.32.0, 1.33.0, 1.34.0, 1.34.1, 1.34.2, 1.34.3, 1.34.4, 1.35.0, 1.35.1, 1.36.0, 1.36.1, 1.36.2, 1.37.0, 1.37.1, 1.38.0, 1.38.1, 1.38.2, 1.38.3, 1.38.4, 1.39.0] but these conflict with your requirements or minimum-stability.
- Installation request for gliterd/backblaze-b2 ^1.3 -> satisfiable by gliterd/backblaze-b2[1.3.0].
Installation failed, reverting ./composer.json to its original content.
Hello, in your library laravel-backblaze-b2 you are using the dependency mhetreramesh/flysystem-backblaze
: https://github.com/gliterd/laravel-backblaze-b2/blob/master/composer.json#L18
Maybe it would be a good idea to archive this repository and point to this one, as it's more updated.
Thank you!
deleted
Hey,
I have been trying to figure out why I was getting an empty exception. I got that I've used wrong credentials after debugging as the API response below:
string(62) "{
"code": "unauthorized",
"message": "",
"status": 401
}"
So I ended up in ErrorHandler class. I see that unauthorized code is not mapped. And the default exception throws message key from API response which in this case is empty. It would be nice to throw at least the code in case of empty message.
When trying to download a B2 file using the Client::download
function, I've noticed that we can overwrite the hostname we're connecting to, leaving just the path.
cURL will then correctly complain that an invalid URL is given. That's because we're asking for /b2api/v1/b2_download_file_by_id?whatever instead of https://xxxx.backblazeb2.com/b2api/v1/b2_download_file_by_id?whatever
I think that I only see this because I'm passing in an invalid token, but I think the bug is still valid.
To fix this, I think we need to change src/Client.php's download function and move $this->authorizeAccount()
above the if (isset($options['FileId']))
and $requestOptions = [ ... ]
blocks. authorizeAccount can set the class's downloadUrl
and authToken
variables, and we're relying on these in this function.
I know this isn't technically an issue, but was wondering if anyone could help me out. I have a website that I made for listing files in a bucket and allowing them to be downloaded, from S3. I'm wanting to move to B2 to save some money and I'm glad a PHP SDK exists, but I'm not a professional web dev, so I'm struggling to understand how to utilize this. It looks similar to the AWS SDK, but integrating it in my web page looks to be different. Here is an example of my existing code:
<?php
return [
's3' => [
'bucket' => 'gba.circa.im',
'prefix' => '',
'version' => 'latest',
'region' => 'us-east-2',
'credentials' => array(
'key' => 'xxx',
'secret' => 'xxx'
)
]
];
$objects = $s3->getIterator('ListObjects', [
'Bucket' => $config['s3']['bucket']
]);
?>
<?php foreach($objects as $object): ?>
<li class="block">
<div class="img gba"> </div>
<a href="<?php echo $s3->getObjectUrl($config['s3']['bucket'], $object['Key']); ?>" class="gba">
<?php $link = str_replace('.gba', '', $object['Key']); echo $link; ?>
</a>
</li>
Particularly the anchor part. I need the file path for the download link, and then the file name as well. Any help? I know it's probably not a good place to ask, but figured I'd start at the source.
seems like the newest release SAYS it contains the large file support... but when it is actually installed via composer dependency, the method is not found.
It looks like the commit hash used to create tag 1.1.0 is from August and thus does NOT contain the new methods.
I think maybe you just need to create a new release (1.1.1)?
I'm using this function
$fileList = $client->listFiles([ 'BucketId' => 'YOUR_BUCKET_ID' ]);
Is there a way to access the PHP Object to read the file size, and file location? the properties are there but they are labeled as "protected" in the resulting object?
I use Php Library to backup images to b2 storage. The command was successful, it returned file id but when I access the file by id, 404 error code was shown.
$file = null;
$try_count = 0;
while(!isset($file)){
try{
$try_count++;
echo "Try Count: $try_count \n";
$file = $client->upload([
'BucketName' => $this->bucket_name,
'FileName' => $backup_file_name,
'Body' => fopen($temp_file_path, 'r'),
'FileContentType' => 'image/jpeg'
]);
}catch(\BackblazeB2\Exceptions\B2Exception $e){
$file = null;
$error_message = $e->getMessage();
// Ignore too busy message
if(strpos($error_message,"busy") === false && strpos($error_message,"lucky") === false){
$email_message = "Try Count: $try_count -- B2 Image Backup Error! Error when upload image to B2.<br/>Link: " . $image_url . "<br/>";
$email_message .= "Error Message: " . $error_message . "<br/>";
Yii::$app->netUtils->send_email_to_admin($email_message);
}
echo "Try Count: $try_count -- " . $error_message . "\n";
sleep(1);
}
}
Backblaze allows custom headers on upload, such as X-Bz-Info-b2-content-disposition
which saves a Content-Disposition on the file, allowing you to have your file stored as one name but download as another.
Likewise, on download they allow the b2ContentDisposition
header to override the file name on download.
Given the likelihood that other such headers exist, in the functions upload, download, uploadLargeFile/uploadParts
please allow an extra option Headers
which merges into the default header values if it exists such as
$response = $this->client->guzzleRequest('POST', $uploadUrl, [
'headers' => array_merge([
'Authorization' => $this->authToken,
], $options['Headers'] ?? [])
]);
Happy to submit a PR if you wish.
Error: Warning: Use of undefined constant seconds - assumed 'seconds' (this will throw an Error in a future version of PHP) in /Users/skyrichardson/Documents/Projects/zoombee/b2-php-2/experiment.php on line 6
Hi,
I'm uploading my files in Core Php and Laravel using this repo. But I am always getting 500 or 503 Service Unavailable error was encountered while trying to upload files like 9GB or more.
Please guide me how to resolve these kind of issues and how to handle if I got these errors...
Because I can not handle the errors like 500 or 503.
Please check the attached screenshot.
Thanks
I am looping through multiple files and passing to a recursive function to to upload to a B2 bucket like so:
private function upload($client, $file, $fileInfo, $savePath)
{
try {
$client->upload([
'BucketName' => 'my-bucket-name',
'FileName' => $file->getId() . '/' . $fileInfo->getFilename(),
'Body' => fopen($savePath .'/' . $fileInfo->getFilename(), 'r')
]);
} catch (Exception $e) {
$this->upload($client, $file, $fileInfo, $savePath);
}
}
The problem is that with multiple file uploads it is expected behaviour for B2 to occasionally fail. See here for 'Uploading Large Files' and 'Code Structure' - https://www.backblaze.com/b2/docs/uploading.html
The error I get after several successful file uploads looks like this
In ErrorHandler.php line 36: Received error from B2: c002_v0001118_t0038 is too busy
The problem here is firstly that the real error and response code is hidden, and secondly even though I am in a try catch block, it doesn't catch the exception.
My question is how should I handle multiple large file uploads to handle these expected (and other) potential exceptions?
Thanks
It would be great if the repo README was updated to reflect this:
ApplicationKey is not supported yet, please use MasterKey only
You get keyID and applicationKey you need to use when you generate a Master Application Key.
$client = new Client('keyID', 'applicationKey', $options);
Due to Undefined variable: apiUrl
.
When B2 returns
{
"code": "unauthorized",
"message": "",
"status": 401
}
this package will only show Received error from B2:
. Which was annoying because this took me longer than it should to troubleshoot. I suggest you default to the code
if the message
is empty.
Hey there,
Library works great with "master" application key. But it wont work with "Application Key". Am i wrong or anyone else faced same issue ?
Thanks!
The b2_list_file_names
method allows you to specify a delimiter (generally "/" and a prefix (from where to search)). This allows it to be used more like a regular file storage, and is more performant with large file trees. Have you considered adding support for these two optional arguments? Implementation is rather trivial, see Koenvh1@39b9d44
Hi, I've noticed that methods like Client::upload()
do not document the exceptions that can be thrown. At first glance, it looks like these methods may either throw a Guzzle RequestException
if the request fails, a B2Exception
, or any other BackblazeB2\Exceptions\*
exception if the response is a non-200
.
That makes a lot of potential exceptions that can be thrown, and they do not share a common interface.
Would you be willing to accept a PR to:
BackblazeB2\Exceptions\*
exceptions extend B2Exception
Client
methods to throw either a RequestException
or a B2Exception
: /**
* Uploads a file to a bucket and returns a File object.
*
* @param array $options
*
* @return File
*
* @throws \GuzzleHttp\Exception\RequestException If the request fails.
* @throws \BackblazeB2\Exceptions\B2Exception If the B2 server replies with an error.
*/
public function upload(array $options)
{
This would work without a BC break, and would make the code more solid, with proper error handling.
Client error: `GET https://api.backblazeb2.com/b2api/v1//b2_authorize_account` resulted in a `404 Not Found` response:
{
\"code\": \"not_found\",
\"message\": \"/b2api/v1//b2_authorize_account\",
\"status\": 404
}
This seems to have only occurred recently. Removing the extra forward slash after v1
seems to fix the issue.
Warning: A non-numeric value encountered in /Users/skyrichardson/Documents/Projects/zoombee/b2-php-gliterd/vendor/gliterd/backblaze-b2/src/Client.php on line 45
Line 45
// set reauthorize time to force an authentication to take place $this->reAuthTime = Carbon::now('UTC')->subSeconds($this->authTimeoutSeconds * 2);
Backblaze has upgraded API to V2. Can you update to be compatible? thank you!
Hi guys,
With the latest commit to the composer file to use Guzzle 6|7 it completely breaks the library unless version 6 is explicitly required before hand. The issue seems to be related to /Http/Client.php
not conforming to the Psr\Http\Message\ResponseInterface
in the latest version of Guzzle.
Here is the error when trying to upload something to B2:
PHP Fatal error: Declaration of BackblazeB2\Http\Client::request($method, $uri = NULL, array $options = Array, $asJson = true) must be compatible with GuzzleHttp\Client::request(string $method, $uri = '', array $options = Array): Psr\Http\Message\ResponseInterface in /gliterd/backblaze-b2/src/Http/Client.php on line 43
Thanks for the help.
Wie sollte uploadlargefile verwendet werden? Ich hoffe, Sie können mir helfen, vielen Dank
Hi,
There's a sample for a large zip file (25Go) ?
Thx
$fileList = $client->listFiles([ 'BucketId' => '6182a9b37d82f0206b8f0233' ]);
print_r($fileList);
BackblazeB2\File Object ( [id:protected] => 4_z6182a9b37d82f0206b8f061b_f100636c8f41465a9_d20190215_m224636_c002_v0001111_t0024 [name:protected] => cosas1.txt [hash:protected] => [size:protected] => 11 [type:protected] => [info:protected] => [bucketId:protected] => [action:protected] => [uploadTimestamp:protected] => )
How use json_encode($fileList); ? 😢 😭
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.