Replies: 1 comment
-
|
This has been fixed in v12. The responsive image URL construction now correctly handles base URLs that contain query strings (such as Azure SAS tokens). The filename is inserted into the path portion before the query string, and version parameters use |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When using Azure Blob Storage with SAS token authentication, responsive image URLs are malformed because the filename is concatenated after the SAS token query string.
ResponsiveImage.php:46 does:
php$url = $urlGenerator->getResponsiveImagesDirectoryUrl() . rawurlencode($this->fileName);
https://storage.blob.core.windows.net/media/1/responsive/?se=...&sig=.../filename.jpg
https://storage.blob.core.windows.net/media/1/responsive/filename.jpg?se=...&sig=...
Root cause:
The UrlGenerator interface only has getResponsiveImagesDirectoryUrl() which returns the directory URL including the SAS token. The filename is then concatenated outside the URL generator, placing it after the query string.
Proposed solution:
Add a new method to the UrlGenerator interface:
phppublic function getResponsiveImageUrl(string $fileName): string;
Default implementation in DefaultUrlGenerator:
phppublic function getResponsiveImageUrl(string $fileName): string
{
return $this->getResponsiveImagesDirectoryUrl() . rawurlencode($fileName);
}
Update ResponsiveImage.php:46:
php$url = $urlGenerator->getResponsiveImageUrl($this->fileName);
This allows custom URL generators to properly handle signed URLs by building the complete path before generating the signature.
Workaround:
Currently the only workaround is extending the Media model and overriding getSrcset().
Environment:
PHP: 8.4.17
Laravel: 12.42.0
spatie/laravel-medialibrary: 11.17.7
Storage: Azure Blob Storage with matthewbdaly/laravel-azure-storage
Beta Was this translation helpful? Give feedback.
All reactions