Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Dropbox Api Laravel Package

spatie/dropbox-api

Minimal PHP client for Dropbox API v2 by Spatie. Provides core endpoints used by their Flysystem Dropbox adapter—create folders, list directories, fetch temporary links, and more. Easy to install via Composer and use with an auth token.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require spatie/dropbox-api
    

    Register the service provider in config/app.php (if not auto-discovered):

    Spatie\Dropbox\DropboxServiceProvider::class,
    
  2. First Use Case: Authenticate and list files in a root folder:

    use Spatie\Dropbox\Client;
    
    $client = new Client(config('services.dropbox.token'));
    $files = $client->listFolder('/');
    
  3. Configuration: Add your Dropbox OAuth2 token to .env:

    DROPBOX_TOKEN=your_access_token_here
    

    Publish the config file (optional):

    php artisan vendor:publish --provider="Spatie\Dropbox\DropboxServiceProvider"
    

Implementation Patterns

Core Workflows

  1. File Operations:

    • Upload/download files via uploadFile()/downloadFile() with local paths or streams.
    • Example:
      $client->uploadFile('/local/path.txt', '/remote/path.txt');
      $client->downloadFile('/remote/path.txt', '/local/download.txt');
      
  2. Folder Management:

    • Create folders recursively with createFolder().
    • Delete folders with deleteFolder() (empty only).
    • Example:
      $client->createFolder('/projects/2023');
      $client->deleteFolder('/projects/2022');
      
  3. Metadata & Sharing:

    • Fetch file metadata with getMetadata().
    • Generate shareable links with getTemporaryLink() or getPermanentLink().
    • Example:
      $metadata = $client->getMetadata('/file.txt');
      $link = $client->getTemporaryLink('/file.txt', 3600); // Expires in 1 hour
      
  4. Large File Handling:

    • Use chunked uploads via uploadFileWithChunking() for files > 150MB.
    • Example:
      $client->uploadFileWithChunking('/large/video.mp4', '/remote/video.mp4');
      

Integration Tips

  • Laravel Filesystem: Combine with spatie/flysystem-dropbox for seamless integration:

    use Spatie\Dropbox\DropboxFilesystem;
    
    $filesystem = new DropboxFilesystem($client);
    $filesystem->put('remote-file.txt', 'content');
    
  • Queue Jobs: Offload long-running operations (e.g., large uploads) to queues:

    UploadDropboxFile::dispatch($localPath, $remotePath)->onQueue('dropbox');
    
  • Event Listeners: Trigger events post-upload/download (e.g., notifications):

    $client->uploadFile(...);
    event(new FileUploaded($remotePath));
    

Gotchas and Tips

Pitfalls

  1. Token Management:

    • Never hardcode tokens. Use Laravel’s .env or a secure secrets manager.
    • Rotate tokens periodically via Dropbox’s App Console.
  2. Rate Limits:

    • Dropbox enforces API rate limits.
    • Cache responses aggressively for metadata/listing operations.
  3. Path Handling:

    • Ensure paths are forward-slash (/) separated, even on Windows.
    • Trailing slashes in folder paths may cause issues (e.g., /folder/ vs /folder).
  4. Large File Quirks:

    • Chunked uploads require the file to be seekable (e.g., local files or streams).
    • Monitor upload progress manually (the package lacks built-in callbacks).
  5. Permissions:

    • The token must have full Dropbox access (not just app_folder).
    • Test with a sandbox account first.

Debugging

  • Enable Debugging: Set SPATIE_DROPBOX_DEBUG=true in .env to log raw API responses.
  • Common Errors:
    • 401 Unauthorized: Invalid/expired token.
    • 403 Forbidden: Insufficient permissions.
    • 404 Not Found: Path does not exist.
    • Fix: Validate paths and token scope.

Extension Points

  1. Custom Endpoints: Extend the Client class to add unsupported API methods:

    class CustomClient extends Client {
        public function customMethod() {
            return $this->request('POST', '/custom-endpoint', []);
        }
    }
    
  2. Webhooks: Use Dropbox’s webhook events to trigger Laravel jobs:

    Route::post('/dropbox/webhook', function (Request $request) {
        event(new DropboxWebhookReceived($request->input()));
    });
    
  3. Testing: Mock the client for unit tests:

    $mockClient = Mockery::mock(Spatie\Dropbox\Client::class);
    $mockClient->shouldReceive('listFolder')->andReturn(['files' => []]);
    

Performance Tips

  • Batch Operations: Use listFolderContinue for paginated results (handled automatically by the package).
  • Caching: Cache metadata for frequently accessed files:
    $metadata = Cache::remember("dropbox:metadata:{$path}", now()->addHours(1), function () use ($client, $path) {
        return $client->getMetadata($path);
    });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport