2017 © Pedro Peláez
 

library flysystem-azure

Flysystem adapter for Windows Azure (Fork of league/flysystem-azure)

image

ijin82/flysystem-azure

Flysystem adapter for Windows Azure (Fork of league/flysystem-azure)

  • Monday, February 26, 2018
  • by ijin82
  • Repository
  • 1 Watchers
  • 15 Stars
  • 2,690 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 36 Forks
  • 0 Open issues
  • 10 Versions
  • 50 % Grown

The README.md

Software License Total Downloads, (*1)

WARNING! 1.0.7.1 is the last version for Laravel 5+ and PHP7

Azure Blob custom filesystem for Laravel 10+ and PHP8

This solution is mostly hack around thephpleague/flysystem-azure-blob-storage and requires 3+ version.
Tested with Laravel 10, probably supported Laravel 8 & 9, additional tests needed.
Check your solutions carefully before release., (*2)

Why forked?

Needed to integrate with L5+ out of the box, and url method for Storage interface., (*3)

How to install in Laravel application

Install package, (*4)

composer require ijin82/flysystem-azure

Open config/app.php and add this to providers section, (*5)

Ijin82\Flysystem\Azure\AzureBlobServiceProvider::class,

Open config/filesystems.php and add this stuff to disks section, (*6)

'my_azure_disk1' => [
    'driver' => 'azure_blob',
    'endpoint' => env('AZURE_BLOB_STORAGE_ENDPOINT'),
    'container' => env('AZURE_BLOB_STORAGE_CONTAINER1'),
    'blob_service_url' => env('AZURE_BLOB_SERVICE_URL'),
],

Open your .env and add variables for your disk, (*7)

AZURE_BLOB_SERVICE_URL={your-blob-service-url}
AZURE_BLOB_STORAGE_ENDPOINT="DefaultEndpointsProtocol=https;AccountName={your-account-name};AccountKey={your-account-key};"
AZURE_BLOB_STORAGE_CONTAINER1={your-container-name}
  1. You can get AZURE_BLOB_SERVICE_URL variable from Properties section of your Storage account settings. That is an url named PRIMARY BLOB SERVICE ENDPOINT or SECONDARY BLOB SERVICE ENDPOINT.
    Same time that could be Azure CDN address (related to your endpoint) to use it as public address for files URL generation.
  2. You can get AZURE_BLOB_STORAGE_ENDPOINT variable from Access keys section of your Storage account settings. That is named CONNECTION STRING
  3. AZURE_BLOB_STORAGE_CONTAINER1 is the name of your pre-created container, that you can add at Overview section of your Storage account settings.

Storage methods supported

REM Path related to container, you need file prefix only if you need subfolder inside container, (*8)

# Upload example
Storage::disk('disk1')->put('file-folder/file1.png',   
  file_get_contents('/my/file/path/file1.png'),  
  [  
    'mimetype' => 'image/png',  
  ]  
);  

```php, (*9)

Get file URL example

$publicUrl = Storage::disk('disk1')->url('file-folder/file1.png');, (*10)

```php
# Check file exists example
$exists1 = Storage::disk('disk1')->exists('file-folder/file1.png');

```php, (*11)

Get file contents example

$contents = Storage::disk('disk1')->get('file-folder/file1.png');, (*12)

```php
# Delete file example
Storage::disk('disk1')->delete('file-folder/file1.png');

```php, (*13)

Delete directory example

Warning, recursive folder deletion!

Storage::disk('disk1')->deleteDir('file-folder');, (*14)

```php
# Put uploaded file to storage example
# $file could be file path on disk (string) OR type of File|UploadedFile 
Storage::disk('disk1')->putFileAs('file-folder', $file, 'file1.png'); 

How to upload file

public function someUploadFuncName(Request $request)
{
    $file = $request->file('file_name_from_request');  

    // .. file name logic
    // .. file folder logic

    $file->storeAs($fileFolder, $fileName, [
        'disk' => 'my_azure_disk1'
    ]);  

    // save file name logic
    // to create file URL by name later
    // maybe you want to save file name and folder separated
    $fileNameToSave = $folderName . '/' . $diskFileName;

    // .. save file name to DB or etc.
}

How to get file URL

We got file name for selected disk (folder related if folder exists), (*15)

echo Storage::disk('my_azure_disk1')->url($fileName);

That is also working in blade templates like this, (*16)

<a href="{{ Storage::disk('my_azure_disk1')->url($fileName) }}"
    target="_blank">{{ $fileName }}</a>

How to delete file

public function someDeleteFuncName($id)
{
    $file = SomeFileModel::findOrFail($id);
    Storage::disk('my_azure_disk1')->delete($file->name);
    $file->delete();

    // go back or etc..
}

Mimetypes (this can be useful)

Sometimes you need to set up mime types manually (for CDN maybe) to get back correct mime type values. You can do that like this (couple types forced for example):, (*17)

$fileConents = Storage::disk('public_or_another_local_disk')->get($file);

$forcedMimes = [
    'js' => 'application/javascript',
    'json' => 'application/json',
];

$fileExt = \File::extension($file);

if (array_key_exists($fileExt, $forcedMimes)) {
    $fileMime = $forcedMimes[$fileExt];
} else {
    $fileMime = mime_content_type(Storage::disk('public_or_another_local_disk')->path($file));
}

Storage::disk('my_custom_azure_disk')->put($fileName, $fileConents, [
    'mimetype' => $fileMime,
]);

You can use wget to get response with headers including Content-Type, (*18)

wget -S https://your-file-host.com/file-name.jpg

Additions

  1. Original repo is here
  2. How to use blob storage from PHP
  3. Feel free to send pull requests and issues.

The Versions

26/02 2018

dev-master

9999999-dev

Flysystem adapter for Windows Azure (Fork of league/flysystem-azure)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge
by Ilya Rogojin

26/02 2018

1.0.7.1

1.0.7.1

Flysystem adapter for Windows Azure (Fork of league/flysystem-azure)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge
by Ilya Rogojin

23/01 2018

1.0.7

1.0.7.0

Flysystem adapter for Windows Azure (Fork of league/flysystem-azure)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge
by Ilya Rogojin

23/01 2018

1.0.6

1.0.6.0

Flysystem adapter for Windows Azure (Fork of league/flysystem-azure)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge
by Ilya Rogojin

18/08 2017

1.0.5

1.0.5.0

Flysystem adapter for Windows Azure (Fork of league/flysystem-azure)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge
by Ilya Rogojin

10/07 2016

1.0.4

1.0.4.0

Flysystem adapter for Windows Azure

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge

19/04 2016

1.0.3

1.0.3.0

Flysystem adapter for Windows Azure

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge

07/07 2015

1.0.2

1.0.2.0

Flysystem adapter for Windows Azure

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge

01/02 2015

1.0.1

1.0.1.0

Flysystem adapter for Windows Azure

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge

21/01 2015

1.0.0

1.0.0.0

Flysystem adapter for Windows Azure

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge