PHP code example of tomshaw / laravel-dropbox

1. Go to this page and download the library: Download tomshaw/laravel-dropbox library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tomshaw / laravel-dropbox example snippets


namespace App\Http\Controllers;

use TomShaw\Dropbox\Dropbox;
use TomShaw\Dropbox\DropboxClient;

class DropboxController extends Controller
{
    public function check()
    {
        Dropbox::check()->app();
    }
}

namespace App\Http\Controllers;

use TomShaw\Dropbox\Dropbox;

class DropboxController extends Controller
{
    public function connect()
    {
        if (request()->has('code')) {

            Dropbox::connect(request('code'), request('state'));

            return redirect()->route('dashboard');
        }

        return redirect()->away(Dropbox::getAuthUrl());
    }
}

namespace App\Http\Controllers;

use TomShaw\Dropbox\Dropbox;

class DropboxController extends Controller
{
    public function revoke()
    {
        Dropbox::revoke();

        return redirect()->route('dashboard');
    }
}

namespace App\Http\Controllers;

use TomShaw\Dropbox\Dropbox;

class DropboxController extends Controller
{
    public function account()
    {
        Dropbox::users()->getCurrentAccount();
    }
}

namespace App\Http\Controllers;

use TomShaw\Dropbox\Dropbox;

class DropboxController extends Controller
{
    public function createfolder(string $path)
    {
        Dropbox::files()->createFolder($path, true);
    }
}

namespace App\Http\Controllers;

use TomShaw\Dropbox\Dropbox;

class DropboxController extends Controller
{
    public function download($id)
    {
        $item = Dropbox::files()->getMetadata($id);

        if ($item) {
            $fileContents = Dropbox::files()->download($item['path_lower']);

            return response($fileContents, 200, [
                'Content-Type' => 'application/octet-stream',
                'Content-Disposition' => 'attachment; filename="' . $item['name'] . '"',
            ]);
        }

        return abort(404);
    }
}

$metadata = Dropbox::files()->downloadTo('/videos/demo.mp4', storage_path('app/demo.mp4'));

namespace App\Http\Controllers;

use TomShaw\Dropbox\Dropbox;
use TomShaw\Dropbox\Enums\WriteMode;

class DropboxController extends Controller
{
    public function upload(string $destinationPath, string $sourceFilePath)
    {
        Dropbox::files()->upload($destinationPath, $sourceFilePath, mode: WriteMode::Add, autorename: false, mute: false, strictConflict: false);
    }
}

use TomShaw\Dropbox\Exceptions\{AuthenticationException, DropboxException, RateLimitException};

try {
    Dropbox::files()->getMetadata('/missing.txt');
} catch (RateLimitException $e) {
    // $e->retryAfter (seconds), after built-in retries were exhausted
} catch (AuthenticationException $e) {
    // Token invalid, revoked, or the OAuth flow has not completed
} catch (DropboxException $e) {
    // $e->status and $e->errorBody['error_summary']
}

namespace App\Http\Controllers;

use TomShaw\Dropbox\Dropbox;
use TomShaw\Dropbox\DropboxClient;

class DropboxController extends Controller
{
    public function sharelink(string $path)
    {
        Dropbox::sharing()->createSharedLinkWithSettings($path, ['requested_visibility' => 'public']);
    }
}

Route::group(['middleware' => ['web', 'auth', 'dropbox']], function () {
  /* Grouped routes */
});

php artisan vendor:publish --provider="TomShaw\Dropbox\Providers\DropboxServiceProvider" --tag=config

php artisan migrate