consilience / flysystem-azure-file-storage
Flysystem adapter for Windows Azure File Storage
Installs: 144 403
Dependents: 2
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 2
Open Issues: 5
Requires
- php: >=8.1.0
- league/flysystem: ^3.0
- microsoft/azure-storage-file: ^1.2.5
Requires (Dev)
- league/flysystem-adapter-test-utilities: ^3.0
- mockery/mockery: ^1.5
- phpunit/phpunit: ^9.0
- vlucas/phpdotenv: ^5.4
This package is auto-updated.
Last update: 2024-11-29 04:58:04 UTC
README
Azure File Storage adapter for Flysystem
This repo is fork of League\Flysystem\Azure
with the underlying Azure API library changed from microsoft/azure-storage
to microsoft/azure-storage-file
.
The original driver supports Azure blob storage, with a flat binary object structure.
This driver supports Azure file storage, which includes directory capabilities.
A separate service provider package for Laravel 5.5+ is available here: https://github.com/academe/laravel-azure-file-storage-driver The service provider allows Azure File Storage shares tbe be used as a native filesystem within Laravel.
Installation
Install package
composer require consilience/flysystem-azure-file-storage
How to use this driver
Note: if you are using Laravel then the filesystem driver will wrap and abstract all of this for you.
use League\Flysystem\Filesystem; use Consilience\Flysystem\Azure\AzureFileAdapter; use MicrosoftAzure\Storage\File\FileRestProxy; use Illuminate\Support\ServiceProvider; // A helper method for constructing the connectionString may be usedful, // if there is a demand. $connectionString = sprintf( 'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s', '{storage account name}', '{file storage key}' ); $config = [ 'endpoint' => $connectionString, 'container' => '{file share name}', // Optional to prevent directory deletion recursively deleting // all descendant files and direcories. //'disableRecursiveDelete' => true, // Optional driver options can also be added here. e.g. CacheControl, Metadata. ]; $fileService = FileRestProxy::createFileService( $connectionString, [] // $optionsWithMiddlewares ); $filesystem = new Filesystem(new AzureFileAdapter( $fileService, $config, 'optional-directory-prefix' )); // Now the $filesystem object can be used as a standard // Flysystem file system. // See https://flysystem.thephpleague.com/api/ // A few examples: $content = $filesystem->read('path/to/my/file.txt'); $resource = $filesystem->readResource('path/to/my/file.txt'); $success = $filesystem->createDir('new/directory/here'); $success = $filesystem->rename('path/to/my/file.txt', 'some/other/folder/another.txt'); // The URL of a file can be found like this: $url = $filesystem->getAdapter()->getUrl('path/to/my/foo.bar');
Testing
Set up .env
and run live tests:
composer install
vendor/bin/phpunit --testsuite flysystem-azure-live-tests
These will create/delete a few test files and directories in the root of the Azure file share.