wesllenalves / laravel-azure-storage-wesllen
适用于 Laravel 的 Storage API 的 Microsoft Azure Blob Storage 集成
Requires
Requires (Dev)
- infection/infection: ^0.26.15
- mockery/mockery: ^1.4
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.22
- pestphp/pest-plugin-laravel: ^1.3
- php-coveralls/php-coveralls: ^2.1
- phpcompatibility/php-compatibility: ^9.3
- phpunit/phpunit: ^9.3
- psy/psysh: ^0.11
- slevomat/coding-standard: ^7.2
- squizlabs/php_codesniffer: ^3.6
- vimeo/psalm: ^4.19
This package is auto-updated.
Last update: 2024-09-28 00:14:17 UTC
README
适用于 Laravel 的 Storage API 的 Microsoft Azure Blob Storage 集成。
这是一个针对 Laravel 文件存储 API 的自定义驱动,该 API 本身建立在 Flysystem 3 之上。它使用 Flysystem 自己的 Azure Blob Storage 适配器,因此无法轻松添加更多功能——实际上,添加这些功能将超出项目范围。
本项目基于原始项目 matthewbdaly/laravel-azure-storage 衍生,并添加了一些功能。
安装
使用 composer 安装此包
composer require wesllenalves/laravel-azure-storage-wesllen
然后将其添加到 config/filesystems.php
文件中的 disks
部分
'azure' => [ // NB This need not be set to "azure", because it's just the name of the connection - feel free to call it what you want, or even set up multiple blobs with different names 'driver' => 'azure', // As this is the name of the driver, this MUST be set to "azure" 'name' => env('AZURE_STORAGE_NAME'), 'key' => env('AZURE_STORAGE_KEY'), 'container' => env('AZURE_STORAGE_CONTAINER'), 'url' => env('AZURE_STORAGE_URL'), 'prefix' => null, 'connection_string' => env('AZURE_STORAGE_CONNECTION_STRING') // optional, will override default endpoint builder ],
最后,将字段 AZURE_STORAGE_NAME
、AZURE_STORAGE_KEY
、AZURE_STORAGE_CONTAINER
和 AZURE_STORAGE_URL
添加到您的 .env
文件中,并使用相应的凭据。字段 AZURE_STORAGE_URL
是可选的,这允许您设置一个自定义 URL,该 URL 由 Storage::url()
返回,如果使用 $root
容器,则 URL 将返回而不包含容器路径。可以可选地使用 prefix
。如果没有设置,则使用容器根目录。然后您可以将 azure
驱动程序设置为默认驱动程序或云驱动程序,并像平常一样使用它来获取和检索文件。
有关如何使用此驱动程序的详细信息,请参阅 Laravel 文件存储 API 文档。
自定义端点
该软件包支持使用自定义端点,如下例所示
'azure' => [ 'driver' => 'azure', 'name' => env('AZURE_STORAGE_NAME'), 'key' => env('AZURE_STORAGE_KEY'), 'container' => env('AZURE_STORAGE_CONTAINER'), 'url' => env('AZURE_STORAGE_URL'), 'prefix' => null, 'connection_string' => null, 'endpoint' => env('AZURE_STORAGE_ENDPOINT'), ],
然后您可以在 .env
文件中指定合适的 AZURE_STORAGE_ENDPOINT
值
SAS 令牌认证
使用 SAS 令牌认证时,需要端点。值的格式如下:https://[accountName].blob.core.windows.net
'azure' => [ 'driver' => 'azure', 'sasToken' => env('AZURE_STORAGE_SAS_TOKEN'), 'container' => env('AZURE_STORAGE_CONTAINER'), 'url' => env('AZURE_STORAGE_URL'), 'prefix' => null, 'endpoint' => env('AZURE_STORAGE_ENDPOINT'), ],
重试
Azure Storage SDK 包含一个用于重试失败请求的 中间件。要启用重试中间件,请在磁盘的配置选项中添加一个 retry
指令。
'azure' => [ 'driver' => 'azure', // Other Disk Options... 'retry' => [ 'tries' => 3, // number of retries, default: 3 'interval' => 500, // wait interval in ms, default: 1000ms 'increase' => 'exponential' // how to increase the wait interval, options: linear, exponential, default: linear ] ],