lucaf87 / flysystem-pcloud
Fund package maintenance!
LucaF87
Installs: 174
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^8.1
- nette/schema: ^1.2
- pcloud/pcloud-php-sdk: 3.*
Requires (Dev)
- orchestra/testbench: 8.*
- phpunit/phpunit: ^9.5
README
Flysystem adapter for pCloud with support for Laravel v10+.
A PHP library to access pCloud API
Get started
Register your application
In order to use this package, you have to register your application in My applications.
Installation
You can install the package via composer:
composer require lucaf87/flysystem-pcloud
or add the following to composer.json
file
"require": {
"lucaf87/flysystem-pcloud": "1.0"
}
Add the following config to the disk
array in config/filesystems.php
[ 'pCloud' => [ 'driver' => 'pCloud', 'clientId' => env('PCLOUD_CLIENT_ID'), 'clientSecret' => env('PCLOUD_CLIENT_SECRET'), 'accessToken' => env('PCLOUD_ACCESS_TOKEN'), 'locationId' => env('PCLOUD_LOCATION_ID'), ] ]
Then set the FILESYSTEM_DISK
to pCloud
in your .env
FILESYSTEM_DISK=pCloud
Publish configuration file
php artisan vendor:publish --provider="LucaF87\PCloudAdapter\Providers\CustomPCloudServiceProvider" --force
Add the following to your .env
PCLOUD_CLIENT_ID=[Get this from https://docs.pcloud.com/my_apps/]
PCLOUD_CLIENT_SECRET=[Get this from https://docs.pcloud.com/my_apps/]
PCLOUD_ACCESS_TOKEN=[leave blank]
PCLOUD_LOCATION_ID=[leave blank]
PCLOUD_LOCAL_FILE_KEEP_ALIVE=60
Generate Auth
Artisan
php artisan flysystem-pcloud:token
Manual
Generate Authorize Code, Navigate to below link (Replace CLIENT_ID with your application Client ID) https://my.pcloud.com/oauth2/authorize?client_id=CLIENT_ID&response_type=code
After you get the access code and the hostname, next step is to generate Access Token. **Before you navigate to below link, make sure to replace Client ID, Secret and Access Code & THE HOST NAME (api.pcloud.com) with what was on the page before https://api.pcloud.com/oauth2_token?client_id=xxxxxxxxx&client_secret=xxxxxxxxx&code=xxxxxxxxx
Copy the access_token and the locationid to the .env
Example
Storage::disk('pCloud')->putFileAs('files', new File('/tmp/file.txt'), 'file-name.txt'); Storage::disk('pCloud')->exists('/files/file-name.txt')); $full_path = Storage::disk('pCloud')->get('/files/file-name.txt');
Download file in local storage and return the full path
$full_path = Storage::disk('pCloud')->get('/files/file-name.txt');
Get a cloud link of a file (It may give problems with different IP addresses)
$url = Storage::disk('pCloud')->fileUrl('/files/file-name.txt'));
Download file in local storage and return the content of a file
$contents = Storage::disk('pCloud')->readStream('/files/file-name.txt');
Deleting a file:
Storage::disk('pCloud')->delete('/files/file-name.txt');
Deleting a directory:
Storage::disk('pCloud')->deleteDirectory('/files')); Storage::disk('pCloud')->deleteDirectory('/files/test'));
Getting the mimetype of a file
$mimeType = Storage::disk('pCloud')->mimeType('/files/file-name.txt');
Get the info of a file
$bytes = Storage::disk('pCloud')->fileInfo('/files/file-name.txt');
Get a list of files
$files = Storage::disk('pCloud')->files('/files'));
Clean local storage
Since pCloud needs to download files locally in order to access them, I created a command to delete files from local storage older than 1 hour (parameter customizable from config). You just have to schedule it inside the Console/Kernel.php file
php artisan flysystem-pcloud:clean-local-storage
Testing
composer test
Credits
License
The MIT License (MIT). Please see License File for more information.