Laravel Dropbox api File Upload example using league/flysystem-dropbox

Laravel Dropbox api File Upload example using league/flysystem-dropbox

In this post we will give you information about Laravel Dropbox api File Upload example using league/flysystem-dropbox. Hear we will give you detail about Laravel Dropbox api File Upload example using league/flysystem-dropboxAnd how to use it also give you demo for it if it is necessary.

Dropbox is a file hosting service and operated by American company Dropbox. They provides cloud storage, file synchronization and personal cloud software. Dropbox is very popular for file synchronization and cloud storage in todays. We can store large file on dropbox and share with someone, as well as we can store database backup in dropbox. Most of the people choose dropbox for cloud storage.

In this post i am going to give you example of how to upload file in our dropbox account using league/flysystem-dropbox package. as well as we also get uploaded file share link and view link that way if we need to store it on database then we can store on db. This posts i give you simple example to store file in dropbox account using Dropbox Client API. You have to just follow few step and you can run example.

Step 1: Installation Package

In this step we have to install league/flysystem-dropbox package and that way we can use Dropbox Client API method so first run bellow command.

composer require league/flysystem-dropbox

Step 2: Token and Secret Configration

we need to require create app on dropbox website that way we can get token and secret so if you don’t have account then you can create from here : Create App.

After create new app you can find token and secret. you have to copy that and add on .env file this way:

.env

DROPBOX_TOKEN=app_token

DROPBOX_SECRET=app_secret

Step 3: Create route and controller

In this step we need to create route and controller for simple example that way you can understand very well. So first create route this way.

app/Http/routes.php

Route::get('dropboxFileUpload', 'HomeController@dropboxFileUpload');

Ok, now your HomeController we have to add dropboxFileUpload() this way, in this example i have img folder on public folder and admin.png image inside on that folder, after run this example it will go on dropbox account:

app/Http/Controllers/HomeController.php


namespace AppHttpControllers;


use AppHttpRequests;

use IlluminateHttpRequest;

use DropboxClient;

use DropboxWriteMode;


class HomeController extends Controller

{

/**

* Create a new controller instance.

*

* @return void

*/

public function __construct()

{

$this->middleware('auth');

}


public function dropboxFileUpload()

{

$Client = new Client(env('DROPBOX_TOKEN'), env('DROPBOX_SECRET'));


$file = fopen(public_path('img/admin.png'), 'rb');

$size = filesize(public_path('img/admin.png'));

$dropboxFileName = '/myphoto4.png';


$Client->uploadFile($dropboxFileName,WriteMode::add(),$file, $size);

$links['share'] = $Client->createShareableLink($dropboxFileName);

$links['view'] = $Client->createTemporaryDirectLink($dropboxFileName);


print_r($links);

}

}

Ok, now you can run example and see…..

Hope this code and post will helped you for implement Laravel Dropbox api File Upload example using league/flysystem-dropbox. 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 *

41  +    =  46

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