Are custom URLs really supported?
lcobucci opened this issue · 2 comments
We're configuring Azurite in our development environment and, since the URL isn't overridden on the Azure client, things don't work.
I've managed to make it well by playing with the provider and configuring the BlobEndpoint
on the Azure client (it works 100% with only Flysystem azure adapter, btw):
<?php
namespace Matthewbdaly\LaravelAzureStorage;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\ServiceProvider;
use League\Flysystem\Filesystem;
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
use function sprintf;
/**
* Service provider for Azure Blob Storage
*/
final class AzureStorageServiceProvider extends ServiceProvider
{
public function boot(): void
{
Storage::extend('azure', static function (Application $app, array $config): Filesystem {
$config['client'] = self::createClient($config);
$adapter = new AzureBlobStorageAdapter(
$config['client'],
$config['container'],
$config['url'] ?? null,
$config['prefix'] ?? null
);
return new Filesystem($adapter, $config);
});
}
/** @param array<string, string|null> $config */
private static function createClient(array $config): BlobRestProxy
{
$endpoint = sprintf(
'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s;',
$config['name'],
$config['key']
);
if (isset($config['blob_endpoint'])) {
$endpoint .= sprintf('BlobEndpoint=%s;', $config['blob_endpoint']);
}
return BlobRestProxy::createBlobService($endpoint);
}
}
Is there any reason why you haven't used this approach on this package?
The custom URL implementation came from this pull request and I've never actually had the occasion to use it myself as it's been a while since I last used Azure Blob Storage. I'm not aware of any issues with it, but it was a year ago that pull request was merged in so things could have changed in the meantime.
If you want to submit your changes as a pull request, I'm happy to take a look.
@matthewbdaly now I realise the misunderstanding!!
I assumed that the URL config was for a customised Azure blob storage endpoint (allowing for my use case) and not for CDNs.
Thanks for your input! Since I don't need the URL generation on my side but do need a custom endpoint I'll remove this lib and use a custom provider for now.
I'm not sure if you want to provide this new feature (custom blob storage endpoint), so I've adjusted the snippet to merge what you have here and what I'm using on my application. Feel free to use or not 👍
Thanks again 😄