PHP code example of jeddsaliba / azure-blob-url-generator

1. Go to this page and download the library: Download jeddsaliba/azure-blob-url-generator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jeddsaliba / azure-blob-url-generator example snippets


'providers' => [
    // ...
    Jeddsaliba\AzureBlobUrlGenerator\UrlGeneratorServiceProvider::class,
],

'url_generator' => \Jeddsaliba\AzureBlobUrlGenerator\Services\UrlGeneratorService::class,

'disks' => [
    'azure' => [
        'driver' => 'azure-storage-blob',
        'sasToken' => env('AZURE_STORAGE_SAS_TOKEN'),
        'container' => env('AZURE_STORAGE_CONTAINER'),
        'endpoint' => env('AZURE_STORAGE_ENDPOINT'),
        'connection_string' => sprintf(
            'BlobEndpoint=%s;SharedAccessSignature=%s',
            env('AZURE_STORAGE_ENDPOINT'),
            env('AZURE_STORAGE_SAS_TOKEN')
        ),
    ],
],

// Add media to a model
$yourModel->addMedia($pathToFile)
    ->toMediaCollection('documents', 'azure');

// Get the Azure Blob SAS URL
$media = $yourModel->getFirstMedia('documents');
$url = $media->getUrl();  // Returns full URL with SAS token

// Get a temporary URL (uses same SAS token - ensure your SAS has appropriate expiration)
$temporaryUrl = $media->getTemporaryUrl(now()->addHours(1));
bash
php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="medialibrary-config"