Code Monkey home page Code Monkey logo

laravel-backblaze-b2's Introduction

laravel-backblaze-b2

Author Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Visit (https://secure.backblaze.com/b2_buckets.htm) and get your account id, application key.

The Laravel Backblaze B2 Storage Service Provider give provision for for laravel storage to use blackblaze as their storage system. It uses the Backblaze B2 SDK & Flysystem Adapter to communicate with the Backblaze b2 API.

Install

Via Composer

composer require gliterd/laravel-backblaze-b2

In your app.php config file add to the list of service providers:

\Gliterd\BackblazeB2\BackblazeB2ServiceProvider::class,

Add the following to your filesystems.php config file in the disks section:

'b2' => [
    'driver'         => 'b2',
    'accountId'      => '',
    'applicationKey' => '',
    'bucketName'     => '',
    'bucketId'       => '', //optional
],

Using ApplicationKey instead of MasterKey

If you specify only the bucket name, your application key must be the master key. However, if you specify both bucket name and bucket id, you do not need the master key and can use a single-bucket key. Fetch your bucket id using the b2 command line tool b2 get-bucket <bucketName>

Usage

Just use it as you normally would use the Storage facade.

\Storage::disk('b2')->put('filename.txt', 'My important content');

and

\Storage::disk('b2')->get('filename.txt')

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-backblaze-b2's People

Contributors

mhetreramesh avatar mlambley avatar remzikocak avatar ziming 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

Watchers

 avatar  avatar  avatar  avatar

laravel-backblaze-b2's Issues

Cant Get Url in laravel

Calling URL in laravel
Storage::disk('s3')->url($filename)
returns an error of no url method.
do you have a way to fix this?
Thanks!

[Bug] Incorrect logic in parameter check

Detailed description

Storage::extend('b2', function ($app, $config) {
if (!(
isset($config['accountId']) ||
isset($config['applicationKey']) ||
isset($config['bucketName']))) {
throw new BackblazeB2Exception('Please set all configuration keys. (accountId, applicationKey, bucketName)');
}

It looks like that logic is wrong. It will only fail if ALL of them are not set. You can verify this with the following test code:

testOr(true, true); //string(4) "good"
testOr(true, false); //string(4) "good"
testOr(false, true); //string(4) "good"
testOr(false, false); //string(3) "bad"

testAnd(true, true); //string(4) "good"
testAnd(true, false); //string(4) "bad"
testAnd(false, true); //string(4) "bad"
testAnd(false, false); //string(3) "bad"

function testOr($a, $b) {
    if (!($a || $b)) { 
        var_dump('bad');
    } else {
        var_dump('good');
    } 
}

function testAnd($a, $b) {
    if (!($a && $b)) { 
        var_dump('bad');
    } else {
        var_dump('good');
    } 
}

Context

It's right there at the beginning of the module, used by everyone.

Possible implementation

Switch the || to && as demonstrated in the example code above

Your environment

Not relevant. See above for generic code which runs on all versions of PHP and all OS.

Using Laravel with backblaze to make cloud storage site for main personal use but get error

I keep getting this error when trying to download a file. I'm using Backblaze with Laravel as a cloud storage site. The file uploads fine but when to download I get that error and I'm not sure why. This is my first project in laravel and it is for learning purposes.

Getting that error code:

InvalidRequest invalid b2-content-disposition: expected ';' but got Token{type=TOKEN, text='Main.mp4', startPosition=40}

and this in site logs:

[2021-01-16 02:49:51] production.ERROR: Received HTTP status code [400] with message "{"errors":[{"code":215,"message":"Bad Authentication data."}]}" when getting temporary credentials. {"userId":1,"exception":"[object] (League\OAuth1\Client\Credentials\CredentialsException(code: 0): Received HTTP status code [400] with message "{"errors":[{"code":215,"message":"Bad Authentication data."}]}" when getting temporary credentials. at /home/giofeivj/file.gioferox.com/vendor/league/oauth1-client/src/Server/Server.php:445)
[stacktrace]

not sure if you can point me in the right direction of what I might be doing wrong

cant list files without preg match issue

so basically im receiving this error when simply looking in a directory with ->files and ->allFiles methods, the error is in listContents method and shows as:
In BackblazeAdapter.php line 239:

preg_match(): Unknown modifier 'a'

Detailed description

below is my code:

        $dest = "/amp/logs"
        $config['filesystem'] = "b2logs"
        $storage = Storage::disk($config['filesystem']);
        $remote_files = Storage::disk($config['filesystem'])->allFiles("{$dest}");

no matter what i try i get the same error i have tried changing dest to be backslashes, escaping the forward slashes, removed from a slash from the start and added to the end it just has none of it.

environment

PHP 7.1.31
lumen 5.4

Storage::disk('b2')->allDirectories() returns [] but Storage::disk('b2regions')->allFiles() returns a proper list

When calling "allDirectories" on a b2 disk, using the Storage::disk('b2')->allDirectories(); method, I received an empty array instead of the expected list of directories.

However, when asking for "allFiles" instead, using the Storage::disk('b2regions')->allFiles(); method, I received an array containing all the files in the bucket with their ful path which was multiple directories down.

It is important to have the allDirectories method working because it's part of what allows a file manager tool (for instance https://github.com/InfinetyES/Nova-Filemanager) to work properly.

This result was obtained using php 7.1, Apache and MySql running on Ubuntu. Laravel version 5.6.35 and laravel-backblaze-b2 1.1

To reproduce, install laravel-backblaze-b2, configure a disk and using php artisan tinker :

use Illuminate\Support\Facades\Storage;
Storage::disk('b2')->allDirectories();
Storage::disk('b2')->allFiles();

BackblazeB2\Exceptions\B2Exception: Received error from B2

It tried with laravel 5.6

calling;
\Storage::disk('b2')->put('/laravel-project/storage/app/test/2018-08-11-23-55-01.zip', 'My important content');

but getting the error:

BackblazeB2\Exceptions\B2Exception: Received error from B2: 
  File "/laravel-project/vendor/gliterd/backblaze-b2/src/ErrorHandler.php", line 36
  File "/laravel-project/vendor/gliterd/backblaze-b2/src/Http/Client.php", line 28, in BackblazeB2\ErrorHandler::handleErrorResponse
  File "/laravel-project/vendor/gliterd/backblaze-b2/src/Client.php", line 422, in BackblazeB2\Http\Client::request
  File "/laravel-project/vendor/gliterd/backblaze-b2/src/Client.php", line 38, in BackblazeB2\Client::authorizeAccount
  File "/laravel-project/vendor/gliterd/laravel-backblaze-b2/src/BackblazeB2ServiceProvider.php", line 22, in BackblazeB2\Client::__construct
  File "/laravel-project/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php", line 139, in Gliterd\BackblazeB2\BackblazeB2ServiceProvider::Gliterd\BackblazeB2\{closure}
  File "/laravel-project/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php", line 119, in Illuminate\Filesystem\FilesystemManager::callCustomCreator
  File "/laravel-project/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php", line 103, in Illuminate\Filesystem\FilesystemManager::resolve
  File "/laravel-project/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php", line 80, in Illuminate\Filesystem\FilesystemManager::get
  File "/laravel-project/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php", line 221, in Illuminate\Filesystem\FilesystemManager::disk
  File "/laravel-project/app/Console/Commands/Test.php", line 69, in Illuminate\Support\Facades\Facade::__callStatic
  File "unknown", line unknown, in App\Console\Commands\Test::handle
  File "/laravel-project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php", line 29, in call_user_func_array
  File "/laravel-project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php", line 87, in Illuminate\Container\BoundMethod::Illuminate\Container\{closure}
  File "/laravel-project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php", line 31, in Illuminate\Container\BoundMethod::callBoundMethod
  File "/laravel-project/vendor/laravel/framework/src/Illuminate/Container/Container.php", line 564, in Illuminate\Container\BoundMethod::call
  File "/laravel-project/vendor/laravel/framework/src/Illuminate/Console/Command.php", line 183, in Illuminate\Container\Container::call
  File "/laravel-project/vendor/symfony/console/Command/Command.php", line 252, in Illuminate\Console\Command::execute
  File "/laravel-project/vendor/laravel/framework/src/Illuminate/Console/Command.php", line 170, in Symfony\Component\Console\Command\Command::run
  File "/laravel-project/vendor/symfony/console/Application.php", line 865, in Illuminate\Console\Command::run
  File "/laravel-project/vendor/symfony/console/Application.php", line 241, in Symfony\Component\Console\Application::doRunCommand
  File "/laravel-project/vendor/symfony/console/Application.php", line 143, in Symfony\Component\Console\Application::doRun
  File "/laravel-project/vendor/laravel/framework/src/Illuminate/Console/Application.php", line 88, in Symfony\Component\Console\Application::run
  File "/laravel-project/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php", line 122, in Illuminate\Console\Application::run
  File "/laravel-project/artisan", line 37, in Illuminate\Foundation\Console\Kernel::handle

Missing required package B2 SDK PHP

I kept having an error thrown inside BackblazeB2ServiceProvider.php file.

Client class not found, after digging around I had to install https://github.com/cwhite92/b2-sdk-php package first.

And add use ChrisWhite\B2\Client; to BackblazeB2ServiceProvider.php

Fresh install of Laravel 5.6

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.