Php Upload File to Dropbox With Guzzlehttp
README
A minimal implementation of Dropbox API v2
This is a minimal PHP implementation of the Dropbox API v2. Information technology contains only the methods needed for our flysystem-dropbox adapter. We are open all the same to PRs that add extra methods to the client.
Hither are a few examples on how y'all can use the package:
$client = new Spatie\Dropbox\Customer( $authorizationToken); //create a folder $client->createFolder( $path); //listing a folder $customer->listFolder( $path); //get a temporary link $customer->getTemporaryLink( $path);
Back up us
Nosotros invest a lot of resources into creating best in class open source packages. You can support us by buying 1 of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(south) you are using. Y'all'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
Yous can install the package via composer:
composer require spatie/dropbox-api
Usage
The first thing yous need to exercise is become an authorisation token at Dropbox. Dissimilar other companies Dropbox has made this very easy. You can just generate a token in the App Panel for any Dropbox API app. Yous'll find more info at the Dropbox Developer Web log.
With an authorization token you lot can instantiate a Spatie\Dropbox\Client.
$client = new Spatie\Dropbox\Client( $authorizationToken);
or alternatively yous tin implement Spatie\Dropbox\TokenProvider which will provide the access-token from its TokenProvider->getToken(): string method.
If y'all use oauth2 to authenticate and to acquire refresh-tokens and access-tokens, (similar thephpleague/oauth2-client), you can create an adapter that internally takes care of token-expiration and refreshing tokens, and at runtime will supply the access-token via the TokenProvider->getToken(): string method.
(Dropbox announced they volition be moving to short-lived access_tokens mid 2021).
// implements Spatie\Dropbox\TokenProvider $tokenProvider = new AutoRefreshingDropBoxTokenService( $refreshToken); $client = new Spatie\Dropbox\Client( $tokenProvider);
or alternatively yous tin can authenticate as an App using your App Central & Secret.
$customer = new Spatie\Dropbox\Client([ $appKey, $appSecret]);
If yous but need to access the public endpoints you can instantiate Spatie\Dropbox\Client without any arguments.
$customer = new Spatie\Dropbox\Client();
Dropbox Endpoints
Wait in the source code of Spatie\Dropbox\Client to notice the methods you lot can use.
Here'southward an example:
$content = 'hello, world'; $client->upload('/dropboxpath/filename.txt', $content, $mode='add'); $from = '/dropboxpath/somefile.txt'; $to = '/dropboxpath/archive/somefile.txt'; $customer->movement( $from, $to);
If the destination filename already exists, dropbox will throw an Exception with 'to/disharmonize/file/..'
The upload() and motility() methods have an optional extra 'autorename' argument to try and let dropbox automatically rename the file if in that location is such a disharmonize.
Hither's an example:
$from = '/dropboxpath/somefile.txt'; $to = '/dropboxpath/annal/somefile.txt'; $client->move( $from, $to, $autorename=true); // with autorename results in 'somefile (1).txt'
If you do non detect your favorite method, yous can directly use the contentEndpointRequest and rpcEndpointRequest functions.
public office contentEndpointRequest(string $endpoint, array $arguments, $body): ResponseInterface public office rpcEndpointRequest(string $endpoint, assortment $parameters): array
Hither'due south an example:
$client->rpcEndpointRequest('search', ['path' => '', 'query' => 'bat cave']);
If you need to change the subdomain of the endpoint URL used in the API request, you lot can prefix the endpoint path with subdomain::.
Here's an example:
$client->rpcEndpointRequest('content::files/get_thumbnail_batch', $parameters);
Changelog
Delight run into CHANGELOG for more than information what has inverse recently.
Testing
composer examination Contributing
Please run into CONTRIBUTING for details.
Security
If you've institute a bug regarding security please post security@spatie.be instead of using the issue tracker.
Postcardware
You're costless to use this bundle (information technology's MIT-licensed), but if it makes it to your production environment we highly appreciate you sending the states a postcard from your hometown, mentioning which of our package(s) you are using.
Our accost is: Spatie, Kruikstraat 22, 2018 Antwerp, Kingdom of belgium.
We publish all received postcards on our visitor website.
Credits
- Alex Vanderbist
- Freek Van der Herten
- All Contributors
License
The MIT License (MIT). Delight see License File for more information.
Source: https://packagist.org/packages/spatie/dropbox-api
0 Response to "Php Upload File to Dropbox With Guzzlehttp"
Post a Comment