rocksolid/flysystem-azure-blob-storage

Azure Blob Storage adapter for Flysystem v3

Installs: 6

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/rocksolid/flysystem-azure-blob-storage

v1.0.1 2025-12-24 08:36 UTC

This package is auto-updated.

Last update: 2025-12-24 08:38:41 UTC


README

A Laravel Flysystem adapter for Azure Blob Storage using direct HTTP REST API calls (no SDK required).

Features

  • Full Flysystem v3 compatibility
  • Direct Azure REST API integration using Guzzle
  • Shared Key authentication
  • Support for all standard file operations
  • Laravel auto-discovery support
  • No external Azure SDK dependencies

Requirements

  • PHP 8.2 or higher
  • Laravel 11.0 or higher
  • GuzzleHttp 7.0 or higher
  • League Flysystem 3.0 or higher

Installation

composer require rocksolid/azure-blob-storage

Configuration

1. Add Azure credentials to your .env file:

AZURE_STORAGE_ACCOUNT_NAME=your-account-name
AZURE_STORAGE_ACCOUNT_KEY=your-account-key
AZURE_STORAGE_CONTAINER=your-container-name

2. Add a disk configuration to config/filesystems.php:

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

    'azure' => [
        'driver' => 'azure-blob',
        'account_name' => env('AZURE_STORAGE_ACCOUNT_NAME'),
        'account_key' => env('AZURE_STORAGE_ACCOUNT_KEY'),
        'container' => env('AZURE_STORAGE_CONTAINER'),
    ],
],

Usage

Basic File Operations

use Illuminate\Support\Facades\Storage;

// Upload a file
Storage::disk('azure')->put('path/to/file.txt', 'File contents');

// Read a file
$contents = Storage::disk('azure')->get('path/to/file.txt');

// Check if file exists
$exists = Storage::disk('azure')->exists('path/to/file.txt');

// Delete a file
Storage::disk('azure')->delete('path/to/file.txt');

// List files
$files = Storage::disk('azure')->files('directory');

// List all files recursively
$allFiles = Storage::disk('azure')->allFiles('directory');

Streaming Operations

// Upload from stream
$stream = fopen('local-file.txt', 'r');
Storage::disk('azure')->writeStream('path/to/file.txt', $stream);
fclose($stream);

// Download as stream
$stream = Storage::disk('azure')->readStream('path/to/file.txt');

Directory Operations

Azure Blob Storage does not have real directories, but you can simulate them using empty files.

// Create directory (creates a placeholder file)
Storage::disk('azure')->makeDirectory('path/to/directory');

// Check if directory exists
$exists = Storage::disk('azure')->directoryExists('path/to/directory');

// Delete directory
Storage::disk('azure')->deleteDirectory('path/to/directory');

File Metadata

// Get file size
$size = Storage::disk('azure')->size('path/to/file.txt');

// Get last modified time
$timestamp = Storage::disk('azure')->lastModified('path/to/file.txt');

// Get MIME type
$mimeType = Storage::disk('azure')->mimeType('path/to/file.txt');

Copy and Move

// Copy file
Storage::disk('azure')->copy('path/to/source.txt', 'path/to/destination.txt');

// Move file
Storage::disk('azure')->move('path/to/source.txt', 'path/to/destination.txt');

Testing

This package includes comprehensive integration tests using the League Flysystem adapter test utilities.

Running Tests

  1. Install development dependencies:
composer install --dev
  1. Configure your Azure credentials by copying phpunit.xml.dist to phpunit.xml:
cp phpunit.xml.dist phpunit.xml
  1. Update the environment variables in phpunit.xml with your Azure Storage credentials:
<php>
    <env name="AZURE_STORAGE_ACCOUNT" value="your-account-name"/>
    <env name="AZURE_STORAGE_KEY" value="your-account-key"/>
    <env name="AZURE_STORAGE_CONTAINER" value="test-container"/>
</php>

Important: Make sure the test container exists in your Azure Storage account before running tests.

  1. Run the test suite:
vendor/bin/phpunit

License

MIT

Credits

Developed by Rocksolid Development