- How do I install spatie/dropbox-api in a Laravel project?
- Run `composer require spatie/dropbox-api` in your project directory. The package has no additional dependencies beyond PHP 8.0+ and Laravel 8+. Store your Dropbox token in `config/services.php` under the `dropbox` key for easy access.
- Does this package support Dropbox Business accounts?
- Yes, the package fully supports Dropbox Business accounts. Use the same token generation process in the Dropbox App Console, and the client will handle Business API endpoints seamlessly. Ensure your token has the correct permissions for your use case.
- Can I use this package with Laravel’s Filesystem (Storage facade)?
- Yes, this package is designed to work with Spatie’s `flysystem-dropbox` adapter, allowing you to integrate Dropbox with Laravel’s unified `Storage` facade. Install `spatie/flysystem-dropbox` separately and configure it in your `filesystems.php` config.
- How do I handle short-lived Dropbox tokens (OAuth2 refresh flow)?
- The package uses the `TokenProvider` interface, which abstracts token management. For OAuth2 refresh flows, integrate with League’s OAuth2 client or implement a custom provider. Store refresh tokens securely and handle token expiration gracefully in your application logic.
- What Laravel versions does spatie/dropbox-api support?
- The package is compatible with Laravel 8, 9, and 10. It follows Laravel’s semantic versioning and is regularly tested against these versions. Check the package’s changelog or GitHub actions for updates on newer Laravel releases.
- How do I mock Dropbox API calls in PHPUnit tests?
- Use Guzzle’s `createMockHandler` to mock HTTP responses. For example, create a mock handler for the `listFolder` endpoint and inject it into the `Client` instance. The package’s dependency on Guzzle makes this straightforward, but abstract the client in your tests for cleaner mocking.
- Does this package support chunked uploads for large files (>50MB)?
- Yes, the package includes methods like `uploadSessionStart` and `uploadSessionFinish` to handle chunked uploads. Implement retry logic for failed sessions, especially in production, and consider exponential backoff to handle rate limits or transient failures.
- Can I extend the package to add custom Dropbox API endpoints?
- Yes, the package provides `contentEndpointRequest` and `rpcEndpointRequest` methods for custom endpoints. Extend the `Client` class or create a decorator to add unsupported endpoints. Submit pull requests to Spatie if the feature benefits the broader community.
- How should I handle Dropbox API rate limits in Laravel?
- The package includes basic retry logic for 5xx and 429 errors. For production, implement exponential backoff in your application or use Laravel’s `retry` helper. Monitor your API usage via Dropbox’s developer dashboard and cache responses (e.g., folder listings) using Laravel’s cache.
- What are the alternatives to spatie/dropbox-api for Laravel?
- Alternatives include the official Dropbox SDK for PHP (unofficial community wrappers) or third-party libraries like `dropbox/dropbox-sdk`. However, Spatie’s package is minimalist, Laravel-optimized, and actively maintained, making it the best choice for most use cases. Evaluate based on your need for Flysystem integration or custom endpoint support.