We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Using the Laravel Filesystem, it's very easy to use cloud providers as regular filesystems.
By default, Amazon S3 (compatible) filesystems are suppported out-of-the-box.
In my setup, I wanted to use Dropbox instead.
As Laravel's filesystem is based on Flysystem, I started with installing a Flysystem driver for Dropbox:
$ composer install spatie/flysystem-dropbox
The next step is to create a provider under app/Providers/DropboxServiceProvider.php
:
namespace App\Providers;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\ServiceProvider;
use League\Flysystem\Filesystem;
use Spatie\Dropbox\Client;
use Spatie\FlysystemDropbox\DropboxAdapter;
class DropboxServiceProvider extends ServiceProvider
{
public function register()
{
}
public function boot()
{
Storage::extend('dropbox', function ($app, $config) {
$adapter = new DropboxAdapter(new Client(
$config['authorization_token']
));
return new FilesystemAdapter(
new Filesystem($adapter, $config),
$adapter,
$config
);
});
}
}
The provider extends the Storage
class by adding a custom provider called "dropbox" in our example.
FilesystemAdapater
is the link between Flysystem and what Laravel expects.
Don't forget to register your provider in config/app.php
under the key providers
.
return [
// ...
'providers' => [
// ...
App\Providers\DropboxServiceProvider::class,
// ...
],
// ...
];
The next step is to add a new filesystem to config/filesystems.php
:
return [
// ...
'disks' => [
// ...
'dropbox-backup' => [
'driver' => 'dropbox',
'authorization_token' => env('DROPBOX_ACCESS_TOKEN'),
],
],
// ...
];
The last step is to generate an access token for Dropbox and add it to your .env file:
DROPBOX_ACCESS_TOKEN=<your-access-token>
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.