railroad / remotestorage
Remote storage service
Installs: 81 021
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- aws/aws-sdk-php: ^3.0.0
- guzzlehttp/guzzle: ^7.2
- laravel/framework: ^11.9
- league/flysystem: ^3.0
- league/flysystem-aws-s3-v3: ^3.0
Requires (Dev)
- ext-gd: *
- orchestra/testbench: ^9.2
- phpunit/php-code-coverage: ^11.0.1
- phpunit/phpunit: ^11.0.1
This package is auto-updated.
Last update: 2024-11-19 21:01:34 UTC
README
Wrapper for slightly easier use of league/flysystem
with AWS S3 by our Laravel application.
Installation, Configuration, Use
Installation
Run $ composer vendor:publish
to copy the package's configuration file "/config/remotestorage.php" to your application's "/config" directory.
(assuming you're using Composer, Laravel, and AWS S3)
Configuration
Define the following environmental variables with appropriate values:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_DEFAULT_REGION
- AWS_BUCKET
Add the service provider (\Railroad\RemoteStorage\Providers\RemoteStorageServiceProvider
) to the 'providers
array in you application's /config/app.php:
'providers' => [ # ... \Railroad\RemoteStorage\Providers\RemoteStorageServiceProvider::class, ]
Run $ php artisan vendor:publish
to copy the config file and create a remotestorage.php file in your application's /config directory. This will take the values you supplied in the .env file and pass them needed.
Use
Inject the Railroad\RemoteStorage\Services\RemoteStorageService
class where needed
/** @var Railroad\RemoteStorage\Services\RemoteStorageService $remoteStorageService */ protected $remoteStorageService; public function __constructor(Railroad\RemoteStorage\Services\RemoteStorageService $remoteStorageService){ $this->remoteStorageService = $remoteStorageService; }
Include namespace at top of file:
use Railroad\RemoteStorage\Services;
... to save yourself having to specify the namespace everywhere:
/** @var RemoteStorageService $remoteStorageService */ protected $remoteStorageService; public function __constructor(RemoteStorageService $remoteStorageService){ $this->remoteStorageService = $remoteStorageService; }
Responses
read
Usage Example(s)
$file = $this->remoteStorageService->read($filenameRelative);
Parameters
Responses
exists
Usage Example(s)
$exists = $this->remoteStorageService->exists('foo/bar.jpg');
/** * @param Request $request * @return JsonResponse */ public function uploadThumbnailIfDoesNotAlreadyExist(Request $request) { $target = 'foo/' . $request->get('target'); if(!$this->remoteStorageService->exists('foo/')){ $upload = $this->remoteStorageService->put($target, $request->file('file')); throw_if((!$upload), new JsonResponse('Upload product thumbnail failed', 400)); } return new JsonResponse(['exists' => true]); }
Parameters
Responses
delete
Usage Example(s)
$this->remoteStorageService->delete('foo/bar.jpg');
public function deleteThumbnail(Request $request) { $target = $request->get('target'); $delete = $this->remoteStorageService->delete('foo/' . $target); throw_if((!$delete), new JsonResponse('product thumbnail deletion failed', 400)); return new JsonResponse(['deleted' => true]); }
Parameters
Responses
create_dir
[TODO]
rename
[TODO]
copy
[TODO]
get_mimetype
[TODO]
get_timestamp
[TODO]
get_size
[TODO]
delete_dir
[TODO]