Working with Dropbox API to upload file using league/flysystem-dropbox package with example in Laravel 5.2

Working with Dropbox API to upload file using league/flysystem-dropbox package with example in Laravel 5.2

In this post we will give you information about Working with Dropbox API to upload file using league/flysystem-dropbox package with example in Laravel 5.2. Hear we will give you detail about Working with Dropbox API to upload file using league/flysystem-dropbox package with example in Laravel 5.2And how to use it also give you demo for it if it is necessary.

Working with Dropbox API to upload file using league/flysystem-dropbox package with example in Laravel 5.2

Here is a sample example to upload file over dropbox, just follow few step to backup your file data in Laravel 5.2 using league/flysystem-dropbox package.

Benefits with Dropbox which is know as cloud storage is freely upload your files into cloud storage instead of server that means you can backup your application or backup your database to dropbox in Laravel 5.2.

Dropbox have many awesome features to working with files as you can easily share your files with friends or upload bulk of files which take less time to uploading, rename your files, edit your files and many more features there.

Flysystem is a filesystem that give you permission to swap out a local filesystem for a remote one.

There are 3 simple steps to done with file upload in dropbox. Follow each step to store or upload file in your dropbox account using Dropbox Client API.

Step1: Install league/flysystem-dropbox package

Its very easy to install league/flysystem-dropbox package with composer, you have to simply fire this command to use Dropbox Client API.

composer require league/flysystem-dropbox

Step2: Create a Dropbox API App

You will need to have app_token and app_secret to authenticate your account with Dropbox. So create a Dropbox API App first to get app_token and app_secret.

Click here to create Dropbox API App

Now you will get your token and secret key after creating Dropbox API App, just copy that token and put in your filesystems.php within config directory.

  1. 'dropbox'=>[
  2. 'driver'=>'dropbox',
  3. 'key'=>'your-key',
  4. 'secret'=>'your-secret'
  5. ],
 'dropbox' => [            'driver' => 'dropbox',            'key' => 'your-key',            'secret' => 'your-secret'        ],

Step3: Route and Controller

Put following line of code in your routes.php

  1. Route::get('dropbox-upload-file','FileController@dropboxFileUpload');
Route::get('dropbox-upload-file', 'FileController@dropboxFileUpload');

Now create a method in your controller to upload file in dropbox. Here I am creating a FileController and within this controller i add dropboxFileUpload method.

Put these code in your controller.

  1. public functiondropboxFileUpload()
  2. {
  3. $Client=newClient(config('filesystems.dropbox.key'),config('filesystems.dropbox.secret'));
  4. $file=fopen(public_path('images/angular_crud.png'),'rb');
  5. $size=filesize(public_path('images/angular_crud.png'));
  6. $dropboxFileName='/dropboxfile-name.png';
  7. $Client->uploadFile($dropboxFileName,WriteMode::add(),$file,$size);
  8. }
 public function dropboxFileUpload()    {        $Client = new Client(config('filesystems.dropbox.key'), config('filesystems.dropbox.secret'));        $file = fopen(public_path('images/angular_crud.png'), 'rb');        $size = filesize(public_path('images/angular_crud.png'));        $dropboxFileName = '/dropboxfile-name.png';        $Client->uploadFile($dropboxFileName,WriteMode::add(),$file, $size);    }

Don’t forget to use traits to include package at top of controller.

  1. use DropboxClient;
  2. use DropboxWriteMode;
use DropboxClient;use DropboxWriteMode;

If you want to store the file link in your database then use these function to view share link.

  1. $Client->createShareableLink($dropboxFileName);
  2. $Client->createTemporaryDirectLink($dropboxFileName);
$Client->createShareableLink($dropboxFileName);$Client->createTemporaryDirectLink($dropboxFileName);

Now you can use this example to upload file in dropbox in Laravel 5.2

Note: The Dropbox SDK uses 64-bit integers, so your PHP version must support 64-bit integers.

Label :

PHP

Laravel PHP Framework

Dropbox API

API

Web Development

Hope this code and post will helped you for implement Working with Dropbox API to upload file using league/flysystem-dropbox package with example in Laravel 5.2. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

12  +    =  16

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US