consilience / flysystem-azure-file-storage
Windows Azure 文件存储的 Flysystem 适配器
1.0.0
2022-05-31 18:49 UTC
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-08-29 04:06:05 UTC
README
Flysystem 的 Azure 文件存储适配器
这个仓库是 League\Flysystem\Azure 的分支,底层的 Azure API 库已从 microsoft/azure-storage
更改为 microsoft/azure-storage-file
。原始驱动程序支持 Azure Blob 存储,具有扁平的二进制对象结构。此驱动程序支持 Azure 文件存储,包括目录功能。
这里提供了 Laravel 5.5+ 的单独服务提供程序包:https://github.com/academe/laravel-azure-file-storage-driver 服务提供程序允许 Azure 文件存储共享在 Laravel 中作为原生文件系统使用。
安装
安装包
composer require consilience/flysystem-azure-file-storage
如何使用此驱动程序
注意:如果您使用 Laravel,则 文件系统驱动程序 将为您包装和抽象化所有这些。
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');
测试
设置 .env
并运行实时测试
composer install
vendor/bin/phpunit --testsuite flysystem-azure-live-tests
这将创建/删除 Azure 文件共享根目录中的几个测试文件和目录。