matthewbdaly / laravel-azure-storage Goto Github PK
View Code? Open in Web Editor NEWMicrosoft Azure Blob Storage integration for Laravel's Storage API
License: MIT License
Microsoft Azure Blob Storage integration for Laravel's Storage API
License: MIT License
Hi, I'm new to Azure storage. I applied the instructions provided in the ReadMe file.
I don't know how to import or use files in the storage account.
Can you help me set this up so I can use the Azure storage file as the main storage file
I trying to upload the files to different directory based on environment.
For example:
local - https://storagepath.blob.core.windows.net/container_name/{local}/image.jpg
production- https://storagepath.blob.core.windows.net/container_name/{production}/image.jpg
To do so, this is the config
'azure' => [
'driver' => 'azure',
'name' => env('AZURE_STORAGE_NAME'),
'key' => env('AZURE_STORAGE_KEY'),
'container' => env('AZURE_STORAGE_CONTAINER'),
'url' => env('AZURE_STORAGE_URL'),
'prefix' => env('APP_ENV'),
],
So now the files was stored correctly, but i found that when i using Storage::url("image.jpg");
The path returned was "https://storagepath.blob.core.windows.net/container_name/image.jpg" because it using the url in config,
But url customization also won't worked because it always prepend the container name to the end of url we set and become like "https://storagepath.blob.core.windows.net/container_name/local/container_name/image.jpg"
Of course i can add the prefix like Storage::url("local/image.jpg"); but it seem like not a proper way.
I'm not sure is this a bug or not. Appreciate for any suggestions and 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?
Hi there, I believe I managed to set up the package by downgrading guzzle ...etc. I can see the uploaded files in the Azure blob, but when I try to upload files from Laravel to the Blob I get a 500 (Internal Server Error). The message is saying:
"The provided account key '' is not a valid base64 string. It has to pass the check 'base64_decode(<user_account_key>, true)'."
I am using this format for the drive:
'azure' => [
'driver' => 'azure',
'name' => env('AZURE_STORAGE_NAME'),
'key' => env('AZURE_STORAGE_KEY'),
'container' => env('AZURE_STORAGE_CONTAINER'),
'url' => env('AZURE_STORAGE_URL'),
'prefix' => null,
],
I've tried: double/single quotes, removing the '==', switching the keys. I am using the key from 'Access Keys' inside Azure Any ideas on that? pls help
Hello,
Thank you for the package, I have used this for a few years and it has been amazing.
I have recently started using Spatie Media Library with Azure storage, when deleting a media model the related files and directories does not get removed. After looking over the code I have pinned the issue down to the command "exists" getting called on a directory and returning false when the directory exists.
use Illuminate\Support\Facades\Storage;
dd(
Storage::has('16'),
Storage::has('16/'),
Storage::exists('16'),
Storage::exists('16/'),
Storage::allDirectories()
);
Produces:
false
false
false
false
array:1 [▼
0 => "16"
]
If I swap to the local file adapter and add the folder this works as expected.
Exists is called in the media library and is returning false which is leaving the files on the azure storage: Spatie Media Library Filesystem
Storage::deleteDirectory('16');
works as expected and the folder deletes without issue.
Versions:
Laravel: 8.68.1
Azure-storage: 1.6.2
Any help with this would be great,
Thanks
Checklist
This package is just a wrapper for Flysystem's Azure storage backend to integrate it with Laravel's storage API. As such, many problems users may experience with it may actually be issues with Flysystem, the Azure driver for Flysystem, or Microsoft's PHP SDK. To help eliminate these issues, please confirm the following:
Describe the bug
When I add the prefix property and use the Storage::disk('azure')->url($filename) method
prefix in url is returned twice
prefix: my-prefix
filename: 'report.xlsx'
output: https://test.blob.core.windows.net/my-storage/my-prefix/my-prefix/report.xlsx
To Reproduce
Steps to reproduce the behavior:
my-prefix
Expected behavior
output: https://test.blob.core.windows.net/my-storage/my-prefix/report.xlsx
Packages and PHP version
Screenshots
Checklist
Because this project is:
The scope of any changes that can be made can be quite limited. If Flysystem, the Laravel storage API or the Azure PHP SDK don't support the feature you want, then it's very unlikely it can be done. As such, please confirm the following:
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
Checklist
This package is just a wrapper for Flysystem's Azure storage backend to integrate it with Laravel's storage API. As such, many problems users may experience with it may actually be issues with Flysystem, the Azure driver for Flysystem, or Microsoft's PHP SDK. To help eliminate these issues, please confirm the following:
Describe the bug
It seems that this change 6ef1a1a that updated the default disk prefix from null to the actual string 'prefix' is causing issues. I have a project with around 4000 uploaded files. After upgrading this package from 1.6.0 to the latest version, all of my files disappeared.
I noticed that files uploaded after the upgrade would be named "prefix/foo.jpg" instead of just "foo.jpg". Changing the prefix value to an empty string fixed the issue.
To Reproduce
Steps to reproduce the behavior:
Storage::allFiles()
Packages and PHP version
MicrosoftAzure\Storage\Common\Exceptions\ServiceException: Fail:↵Code: 400↵Value: Block blobs are
I have read the documentation, i'm student junior programmer i'have configure as the documentation but when put image to disk have some error.
Storage::disk('azure')->put($fileName,$image);
$path = Storage::url($fileName);
Is your feature request related to a problem? Please describe.
I'd like to instantiate the Filesystem with a connection string like this, which is published in the Azure Portal and which is what is passed as a secret to my docker container via CI/CD:
DefaultEndpointsProtocol=[http|https];AccountName=[yourAccount];AccountKey=[yourKey];BlobEndpoint=<url>
I used to have my own code like this:
$client = BlobRestProxy::createBlobService($connectionString);
$adapter = new AzureBlobStorageAdapter($client, $container, $prefix);
return new Filesystem($adapter);
This is quite concise. Now I have to write a class just to parse the connection string and pass it into this adapter as individual elements. This is more work than I used to do.
Describe the solution you'd like
The adapter should accept a single 'connection_string' configuration element in lieu of separate key. name, endpoint, etc.
Describe alternatives you've considered
Sticking with my own convenience class to return the Filesystem adapter.
I'm using a path prefix
in the configuration, but I noticed that getTemporaryUrl
only considers the container
. I would expect that I could pass a relative path consistent to put
and get
to generate a URL to those files.
"class": "ErrorException",
"message": "Undefined index: endpoint",
"code": 0,
"file": "/www/vendor/matthewbdaly/laravel-azure-storage/src/AzureStorageServiceProvider.php:28",
Since upgrade to 1.3.10, the config/filesystems.php
array for 'azure' MUST contain an 'endpoint' (can be null), otherwise the value is unset and will throw an error at AzureStorageServiceProvider.php:28
.
I'm under the impression that the SAS token is appended to the URL when making a request to a specific resource. The config setting makes it look like it's some sort of copied and pasted string and then provides no details on how it works. Does anyone know how to view a resource with SAS is supposed to work?
Upload , download, list blobs , list containers are API's written using this package.
Problem is each time call is made to any of the API's the default value of "AZURE_STORAGE_CONTAINER" will be taken from .env instead of the value beeing set using config(filesystem.azure.containe => $container_name);
Setting the container everytime just before storage upload/download , config is used to set the AZURE_STORAGE_CONTAINER.
Hi,
This works great for uploading an image, but the content-type is set to "application/octet-stream" which means images will only be downloaded and not open in the user's browser. To open in the browser, the content-type needs to be "image/jpeg".
I have tried to set the content-type at time of upload, and after the upload on the existing blob but with no success.
Please could you provide a solution to change the content-type.
Thank you
Problem 1
- Installation request for matthewbdaly/laravel-azure-storage ^1.4 -> satisfiable by matthewbdaly/laravel-azure-storage[1.4.0].
- Can only install one of: guzzlehttp/guzzle[6.5.x-dev, 7.2.0].
- Can only install one of: guzzlehttp/guzzle[7.2.0, 6.5.x-dev].
- Can only install one of: guzzlehttp/guzzle[6.5.x-dev, 7.2.0].
- Conclusion: install guzzlehttp/guzzle 6.5.x-dev
- Installation request for guzzlehttp/guzzle (locked at 7.2.0, required as ^7.0.1) -> satisfiable by guzzlehttp/guzzle[7.2.0].
So it looks like it's not supported for latest Guzzle 7.2.0 version
Hi guys,
This library work for use Sharepoint Dcouments as Filesystem ??
Thx
Checklist
This package is just a wrapper for Flysystem's Azure storage backend to integrate it with Laravel's storage API. As such, many problems users may experience with it may actually be issues with Flysystem, the Azure driver for Flysystem, or Microsoft's PHP SDK. To help eliminate these issues, please confirm the following:
Describe the bug
When using a configured prefix, the URL returned by the url
method ignores the prefix and is invalid.
To Reproduce
my_prefix
.test.txt
with any content.url()
method.Expected behavior
The URL returned form the url()
method should be correct and contain the prefix configured.
Packages and PHP version
Any
Desktop (please complete the following information):
Any
Smartphone (please complete the following information):
Any
First of all, thank you for this package. If I can get it working, it will be an absolute lifesaver!
I'm currently trying to store data to an Azure Blob Storage account but keep getting
Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required"
whenever I try and do anything.
In the .env file, I've added the following lines:
AZURE_STORAGE_NAME=[THE NAME OF THE STORAGE ACCOUNT]
AZURE_STORAGE_KEY=[KEY1 (TRIED SURROUNDING IT IN DOUBLE QUOTES, SINGLE QUOTATION MARKS, AND NOTHING) FROM THE SETTINGS->ACCESS KEYS PAGE ON THE ABOVE STORAGE ACCOUNT]
AZURE_STORAGE_CONTAINER=[THE CONTAINER I CREATED IN THAT ACCOUNT]
Can you clear up what I'm missing here? I'm sure it's something I'm doing wrong but I can't figure out where I could be messing up.
Thank you!
Could support be added for AAD authentication method as mentioned in the azure storage php repo? https://github.com/Azure/azure-storage-php/
It appears very similar to SAS method but passing account name instead of saskey.
Hi, I managed to set up the storage. However, I have an issue with the video(.mp4) files. I have my blobs set as block blobs ( suitable for streaming) The problem that I face is: it takes 10-20 seconds for a video to load on the browser and I can't seek the video (jump forwards/backward). I browsed the web for a couple of days and I couldn't find much. I found some answers suggesting progressive loading, but in ASP.net. Any idea how to make it in laravel? (sorry if this is not the right place for this question)
Hi,
Thank you so much for creating this. I love it!
I am new to laravel so I might have missed it but is there a way to select a different Container to upload to during run time?
Looks like flysystem have a new version 1.x
Please update it to the latest version
Hi, since a few days I'm experiencing the following problem: the files
method returns also soft deleted files. Is there any option to exclude them from the response?
Thank you
Describe the bug
When using AZURE_STORAGE_CONNECTION_STRING
variable, I receive an
Matthewbdaly\ LaravelAzureStorage \ Exceptions \ KeyNotSet
When using the exact same config in separate variables (AZURE_STORAGE_URL
, AZURE_STORAGE_KEY
etc)
the connection works an no errors are thrown.
Packages and PHP version
I'm wondering if this package support uploading files as blobs directly to azure?
Hi,
We are using Lumen with your library and your commit 628fe40b2154ea0b5545590d3fd92b88e5e830c9 broke our application.
Could you please use Illuminate\Contracts\Container instead? Both Laravel and Lumen applications implement Illuminate\Contracts\Container
Can we convert this project to access using the Storage API directly when the 17th of March Arrives, what are the blockers?
Microsoft have announced the retirement of the Azure Storage PHP client on 17 March 2024. Off the back of this Frank de Jonge, who maintains the Flysystem library and the Azure Storage integration for it, has announced that the Azure Storage integration, will no longer be maintained as of the same date.
This package is entirely dependent on the Azure Storage integration, and by extension the Microsoft client libraries. As such, maintaining it past that point will be impractical. In addition, I myself have never had the occasion to use this package, and only wound up using Azure once when a client insisted on it. I've therefore decided this package will also be retired as at the same date.
If you're using it now, I suggest you consider migrating your existing application off Azure Storage sometime in the next year. If not, you will need to make alternative arrangements for interacting with the REST API.
Hi, I have tried to use this on a Lumen environment. Previously I use S3 filesystem and it works great, but when I install your library with composer install and add the azure disk this error come up. Am I missing something?
lumen.ERROR: InvalidArgumentException: Driver [azure] is not supported. in /var/www/vendor/illuminate/filesystem/FilesystemManager.php:126 Stack trace: #0 /var/www/vendor/illuminate/filesystem/FilesystemManager.php(102): Illuminate\Filesystem\FilesystemManager->resolve('azure') #1 /var/www/vendor/illuminate/filesystem/FilesystemManager.php(79): Illuminate\Filesystem\FilesystemManager->get('azure') #2 /var/www/vendor/illuminate/support/Facades/Facade.php(221): Illuminate\Filesystem\FilesystemManager->disk('azure')
Great project! Thanks so much for it. I am looking at getting the URL for the azure resource. The current implementation only allows to grab the file contents like so:
$fileData = Storage::get($path);
Would then like to let the user download the file. Any thoughts on the best way to handle that?
matthewbdaly/laravel-azure-storage package working great while uploading file to Azure Storage but I'm not able to removing file from Azure Storage
Because this project has no functionality for removing file yet:
Is your feature request related to a problem? Please describe.
We are shifting lots of project from AWS to Azure. Now we are facing issue like removing files
Describe the solution you'd like
function remove_file_azure($file){ return Storage::disk('azure')->delete($file); }
Thankyou so much
It's currently not possible to specify the BlobEndpoint, which is needed in order to use the development storage account
Happy to work on this, probably take a look over the next couple days. Logging here so I don't forget.
Hi,
I'm using this package in our projects and I'm facing an issue when I'm trying to get the Blob client. Actually,
I'm unable to get Blob Client object because it is private property. For this, we need getter method called "getClass()" in AzureBlobStorageAdapter class.
Even I can not extend this class as it is declared as final.
I need below things from your end:
Out of curiosity I just wanted to ask you that is there any reason behind declaring that class as "final" ?
Accessing Blob Client is required for me to get Meta data of the file stored in Blob.
Note: If you want me to submit pull request for this - I can do that.
Thanks
Checklist
This package is just a wrapper for Flysystem's Azure storage backend to integrate it with Laravel's storage API. As such, many problems users may experience with it may actually be issues with Flysystem, the Azure driver for Flysystem, or Microsoft's PHP SDK. To help eliminate these issues, please confirm the following:
Describe the bug
Getting the above error (This driver does not support creating temporary URLs.
) when doing something basic like this:
use Illuminate\Support\Facades\Storage;
Route::get('test/{file}', function ($file) {
$path = "$file";
$url = Storage::disk('azure')->temporaryUrl($path, 60);
return $url;
}
The entry in filesystems.php:
'azure' => [
'driver' => 'azure',
'name' => env('AZURE_STORAGE_NAME'),
'key' => env('AZURE_STORAGE_KEY'),
'container' => env('AZURE_STORAGE_CONTAINER'),
'url' => env('AZURE_STORAGE_URL'),
'prefix' => env('AZURE_STORAGE_PREFIX'),
'retry' => [
'tries' => 3,
'interval' => 500,
'increase' => 'exponential',
],
],
To Reproduce
See code above
Expected behavior
That error not to appear
Desktop (please complete the following information):
Additional context
Unsure of any other additional context I can offer but happy to answer any questions to clarify things.
problem 1
- Installation request for matthewbdaly/laravel-azure-storage ^1.3 -> satisfiable by matthewbdaly/laravel-azure-storage[1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5, 1.3.6, 1.3.7, 1.3.8].
- Can only install one of: guzzlehttp/guzzle[6.5.x-dev, 7.0.1].
- Can only install one of: guzzlehttp/guzzle[7.0.1, 6.5.x-dev].
- Can only install one of: guzzlehttp/guzzle[6.5.x-dev, 7.0.1].
- Conclusion: install guzzlehttp/guzzle 6.5.x-dev
- Installation request for guzzlehttp/guzzle (locked at 7.0.1, required as ^7.0.1) -> satisfiable by guzzlehttp/guzzle[7.0.1].
can not install this package on laravel 8.
can you guide how to install in laravel 8
thanks
How can I upload file in Azure File Share instead of containers. I have a file which is accessible by multiple application.
Hi Matthew,
I have been using the laravel-azure-storage to store documents to a General Purpose V2 account for over a month now. Recently, I have observed that it generates the following error when I try to load slightly larger file sizes (like over 3.7 MB). Is this due to some setting on Azure that limits file sizes? I don't have this issue with smaller files around 2 MB. My post_max_size and upload_max_size are set to 10 MB - so that's not an issue.
"message": "Fail:\nCode: 403\nValue: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.\ndetails (if any): \ufeff<?xml version=\"1.0\" encoding=\"utf-8\"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.\nRequestId:d8b2ceac-601e-0016-2f29-fd17e5000000\nTime:2021-02-07T08:17:46.8684637Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request 'CLyWOIZjBxp0dEJuTUHrrazunQc49AP83kFwVLQvz34=' is not the same as any computed signature. Server used following string to sign: 'PUT\n\n\n\n\napplication/x-www-form-urlencoded\nSun, 07 Feb 2021 08:17:46 GMT\n\n\n\n\n\nx-ms-blob-content-type:application/pdf\nx-ms-blob-type:BlockBlob\nx-ms-client-request-id:601fa22ad0de2\nx-ms-version:2017-11-09\n/somename/invoice/iirfiles/USA_latest.pdf'.</AuthenticationErrorDetail></Error>.",
"exception": "MicrosoftAzure\\Storage\\Common\\Exceptions\\ServiceException",
"file": "/var/www/html/mir/vendor/microsoft/azure-storage-common/src/Common/Internal/ServiceRestProxy.php",
I would really appreciate your advice on this one.
Hi,
I have different modules in my project where files are uploading to same container for example "abc1"
How its possible to use multiple azure storage containers in a single project? so that each module will have different storage on azure.
Regards
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.