Working with Dropbox in Laravel 5

Working with Dropbox in Laravel 5

Often we decide to store uploaded files into the cloud storage instead of our web server. There are many options available and Laravel comes with quite a few options but and can be extended with even more options, let’s see how we can store uploaded files to popular could storage service Dropbox.

What we are building

We are going to build a simple app that will get our uploaded files and store it to Dropbox, to make things simple we will make this app in three simple steps.

1- First step for Upload form, where we will create a form to upload files.

2- Tthe Second step is going to initiate our DropboxStorageRepository and will return the success or failure.

3- Last step will be to create our dedicated Dropbox repository that will house official Dropbox API related stuff such as creating a new connection to Dropbox and uploading files.

Step 1: Setting up our routes and creating our upload form

Here we have a upload form in fileUpload.blade.php view page. This form just containing a file input upload button for uploading any type of file.

app/Http/routes.php

Call the file method in StorageController.

Route::get('upload', 'StorageController@file');

app/Http/Controllers/StorageController.php

StorageController has file method for redirecting a request to our view fileUpload.blade.php page where our main form exist.

public function file() { return view('fileUpload'); }

resources/views/fileUpload.blade.php

This is our upload form which have an obvious post method and ‘files’=>true attribute which is similar to enctype= multipart/form-data required for upload file:


Originally published at www.laravelfeed.com.

Like what you read? Give LaravelFeed a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.