Code Monkey home page Code Monkey logo

backblaze-b2's People

Contributors

benmorel avatar brino avatar fozbek avatar ggiak avatar grahamcampbell avatar koenvh1 avatar matthewhallcom avatar mhetreramesh avatar mlambley avatar remmelt avatar steppinghat avatar stevecoug avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

backblaze-b2's Issues

filtering by prefix is missing

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.

Can't use an up-to-date version of Carbon

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.

Empty message for unauthorized exception

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.

Download URL incorrect if we need to authorize

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.

Wanting to move from AWS to B2

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">&nbsp;</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.

newest release (1.1.0) does not contain uploadLargeFile() method

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)?

accessing file size without downloading

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?

File was uploaded successful but return 404 when access it

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.

I upload above 100 million files to b2 via this library tool and some of them have the above problem, not all of them. Here is my code:

$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);
                }
            }

Allow custom headers on upload and download

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.

Undefined contant seconds'

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

Multiple file uploads returns uncatchable B2 Exception too busy when fails

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

Update documentation to use keyID instead of accountID

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);

Empty error on Unauthorized

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.

Support for delimiters and prefixes

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

Harmonize / document exceptions

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:

  • Make all BackblazeB2\Exceptions\* exceptions extend B2Exception
  • Document 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.

[Fixed in 1.5.2] 404 error on authorize

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

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);

Please update api v2

Backblaze has upgraded API to V2. Can you update to be compatible? thank you!

Guzzle v7 interface issue

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.

listFiles

$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); ? 😢 😭

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.