Search by

maize-tech / laravel-azure-blob-storage

maize-tech

Laravel filesystem driver for Azure Blob Storage, built on the Blob Storage REST API

Package info

github.com/maize-tech/laravel-azure-blob-storage

pkg:composer/maize-tech/laravel-azure-blob-storage

Fund package maintenance!

Maize

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-11-30 15:01 UTC

This package is auto-updated.

Last update: 2026-11-30 15:04:25 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Easily use Azure Blob Storage as a Laravel filesystem disk.

This package adds an azure-blob driver to the Storage facade, so you can work with an Azure container exactly like you would with an S3 bucket. It talks to the Blob Storage REST API directly through Saloon, without depending on the retired microsoft/azure-storage-* PHP SDK.

use Illuminate\Support\Facades\Storage;

Storage::disk('azure')->put('invoices/2026/001.pdf', $pdf);

Storage::disk('azure')->temporaryUrl('invoices/2026/001.pdf', now()->addMinutes(15));

If you come from AWS S3, this is how the concepts map:

AWS S3 Azure Blob Storage
Bucket Container (inside a Storage Account)
Object Blob
Access key / secret Account key, SAS token or Microsoft Entra ID app
Presigned URL SAS URL

Installation

You can install the package via composer:

composer require maize-tech/laravel-azure-blob-storage

The service provider is registered automatically and the package has no config file to publish.

Add a disk to your config/filesystems.php file:

'disks' => [
    // ... other disks

    'azure' => [
        'driver' => 'azure-blob',
        'account' => env('AZURE_STORAGE_ACCOUNT'),
        'container' => env('AZURE_STORAGE_CONTAINER'),

        // 1) Shared Key (storage account access key)
        'key' => env('AZURE_STORAGE_KEY'),

        // 2) ...or a SAS token
        // 'sas_token' => env('AZURE_STORAGE_SAS_TOKEN'),

        // 3) ...or Microsoft Entra ID (App Registration)
        // 'tenant_id' => env('AZURE_TENANT_ID'),
        // 'client_id' => env('AZURE_CLIENT_ID'),
        // 'client_secret' => env('AZURE_CLIENT_SECRET'),

        // ...or a full connection string (from the Azure portal, "Access keys")
        // 'connection_string' => env('AZURE_STORAGE_CONNECTION_STRING'),

        // Optional
        'url' => env('AZURE_STORAGE_URL'),           // public base URL (e.g. a CDN)
        'endpoint' => env('AZURE_STORAGE_ENDPOINT'), // e.g. Azurite or a custom domain
        'root' => '',
        'throw' => false,
    ],
],

The authentication method is picked from the credentials you set. Set the auth option to shared_key, sas or entra_id to choose one explicitly.

Configuration

Shared Key

Add the storage account name and one of its access keys to your .env file:

FILESYSTEM_DISK=azure

AZURE_STORAGE_ACCOUNT=mystorageaccount
AZURE_STORAGE_CONTAINER=uploads
AZURE_STORAGE_KEY=base64-account-key==

You can find the key in the Azure portal under Storage account → Security + networking → Access keys.

SAS token

AZURE_STORAGE_ACCOUNT=mystorageaccount
AZURE_STORAGE_CONTAINER=uploads
AZURE_STORAGE_SAS_TOKEN="sv=2022-11-02&sr=c&sp=racwdl&se=...&sig=..."

The token needs the permissions for the operations you use: r read, a/c/w write, d delete, l list.

A SAS token cannot sign new URLs, so temporaryUrl() and temporaryUploadUrl() are not available with this method.

Microsoft Entra ID

AZURE_STORAGE_ACCOUNT=mystorageaccount
AZURE_STORAGE_CONTAINER=uploads
AZURE_TENANT_ID=00000000-0000-0000-0000-000000000000
AZURE_CLIENT_ID=00000000-0000-0000-0000-000000000000
AZURE_CLIENT_SECRET=your-client-secret

The package uses the OAuth 2.0 client credentials flow. The App Registration needs a data-plane role on the storage account or container, such as Storage Blob Data Contributor: a management role like Contributor is not enough.

Access tokens are cached for 55 minutes with the Saloon cache plugin, in the default cache store. Use the cache_store option to pick another store.

If a token gets revoked, you can clear it so the next request acquires a new one:

use Illuminate\Support\Facades\Storage;

Storage::disk('azure')->getClient()->getConnector()->getCredentials()->tokenProvider->clearToken();

For sovereign clouds, set the authority_host option (for example https://login.microsoftonline.us) together with the matching endpoint.

Custom endpoints

Use the endpoint option to target Azurite, a sovereign cloud or a custom domain. When account is not set, the account name is read from the endpoint:

'azurite' => [
    'driver' => 'azure-blob',
    'endpoint' => 'http://127.0.0.1:10000/devstoreaccount1',
    'key' => env('AZURITE_KEY'),
    'container' => 'uploads',
],

Available options

Option Description Default
account Storage account name from connection_string / endpoint
container Container name (required)
key Account access key (Shared Key)
sas_token SAS token
tenant_id, client_id, client_secret Microsoft Entra ID App Registration
connection_string Azure Storage connection string
auth Force shared_key, sas or entra_id auto-detected
endpoint Blob service endpoint https://{account}.blob.core.windows.net
authority_host Entra ID authority https://login.microsoftonline.com
url Base URL for url() the blob endpoint
temporary_url Base URL for temporary URLs the blob endpoint
root Path prefix inside the container ''
upload_chunk_size Block size in bytes for stream uploads 8388608 (8 MiB)
timeout, connect_timeout HTTP timeouts in seconds 60, 10
cache_store Cache store for tokens and delegation keys default store
throw, read-only, prefix Standard Laravel disk options

As in Laravel, the read-only and prefix options require the league/flysystem-read-only and league/flysystem-path-prefixing packages.

Usage

Basic

Once configured, you can use the disk like any other Laravel disk:

use Illuminate\Support\Facades\Storage;

$disk = Storage::disk('azure');

$disk->put('invoices/2026/001.pdf', $pdf);

$contents = $disk->get('invoices/2026/001.pdf');

$disk->exists('invoices/2026/001.pdf');
$disk->size('invoices/2026/001.pdf');
$disk->lastModified('invoices/2026/001.pdf');
$disk->mimeType('invoices/2026/001.pdf');
$disk->checksum('invoices/2026/001.pdf');

$disk->copy('a.txt', 'b.txt');
$disk->move('b.txt', 'archive/b.txt');
$disk->delete('archive/b.txt');

Directories

$disk->files('invoices');          // ['invoices/readme.txt']
$disk->allFiles('invoices');       // recursive
$disk->directories('invoices');    // ['invoices/2026']

$disk->deleteDirectory('invoices/2025');

Large files

Streams are uploaded in blocks (Put Block + Put Block List) and downloaded as streams, so large files are never loaded fully in memory:

$disk->putFile('avatars', $request->file('avatar'));
$disk->writeStream('backups/db.sql.gz', fopen($path, 'r'));

$stream = $disk->readStream('backups/db.sql.gz');

The block size can be changed with the upload_chunk_size option.

Blob properties and metadata

$disk->put('report.pdf', $pdf, [
    'mimetype' => 'application/pdf',          // detected automatically when omitted
    'cache_control' => 'public, max-age=3600',
    'content_disposition' => 'inline',
    'metadata' => ['customer' => '42'],       // stored as x-ms-meta-* headers
]);

Public URLs

The container must allow anonymous read access, or you can set the url option to a CDN:

$disk->url('images/logo.png');

Temporary URLs

Temporary URLs are signed, time-limited SAS URLs:

$disk->temporaryUrl('invoices/2026/001.pdf', now()->addMinutes(15), [
    'ResponseContentDisposition' => 'attachment; filename="invoice.pdf"',
    'ResponseContentType' => 'application/pdf',
]);

You can also create a signed upload URL: the client must send a PUT request with the returned headers.

['url' => $url, 'headers' => $headers] = $disk->temporaryUploadUrl('uploads/video.mp4', now()->addMinutes(30));

With an account key they are signed as a service SAS. With Entra ID credentials they are signed as a user delegation SAS: the delegation key is cached and the URLs are valid for at most 7 days.

Visibility

Azure Blob Storage has no per-blob ACLs: public access is set on the container. setVisibility() and getVisibility() throw an exception, and the visibility option of put() is ignored.

Low level client

You can access the underlying client to read the blob properties:

$client = Storage::disk('azure')->getClient(); // Maize\BlobStorage\Services\BlobStorageClient

$properties = $client->getBlobProperties('invoices/2026/001.pdf'); // etag, md5, metadata, ...

Testing

composer test

The integration tests run against Azurite and are skipped when it is not running:

npx --package=azurite azurite-blob --inMemoryPersistence --blobHost 127.0.0.1 --blobPort 10000

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.