Temporary/Signed (S3) urls for responsive images #2022
Replies: 1 comment
-
I have solved this by extending the library - it's not the prettiest (or correct?, for that matter) solution, but it works. In my example I use caching to avoid regenerating temporary URLs while they're still valid (fixes browser caching of images, because URL is not refreshed on every page reload). Here are the files: https://spatie.be/docs/laravel-medialibrary/v10/advanced-usage/using-your-own-model
https://spatie.be/docs/laravel-medialibrary/v10/advanced-usage/generating-custom-urls
https://spatie.be/docs/laravel-medialibrary/v10/responsive-images/customizing-the-rendered-html
Now you should be able to generate your image html like this: Maybe someone will refactor and raise a PR for this :) |
Beta Was this translation helpful? Give feedback.
-
I've been working with this package for a bit now and it works like a charm. I only have one question, for the main image and the main url of the conversion the package supports temporary urls when running on S3 (or any other Adapter that supports temporary urls), however the responsive images do not...
Since some use cases/requirements might require that the files are stored privately (and only be available for a specific duration), it seems to me that it should be possible to also generate temporary urls for the responsive variants as well.
An additional idea is that it would be nice to have a config option where you can specify a default duration (int or interval string) and when set, calling
->getUrl
(orResponsiveImage::url
) will instead generate a temporary url so you can use the same method for both situations (for example for local development) without having to add custom logic.Beta Was this translation helpful? Give feedback.
All reactions