'how to create temporary url for custom storage in laravel?
I make a disk in filesystem like:
'avatars' => [
'driver' => 'local',
'root' => storage_path('app/avatars')
],
is it possible / how can I ,create a temporary URL for files in this disk? i tried
return Storage::disk('avatars')->temporaryUrl('pp12.jpeg', now()->addMinutes(5));
but its show me this error:
RuntimeException
This driver does not support creating temporary URLs.
Solution 1:[1]
As noted in the documentation, and by the error message, temporary URLs are a feature of the S3 driver, and are not supported on any other driver.
If you don't want to use S3 to store your files (and you should probably consider doing so since it's a cheap and flexible way of hosting large numbers of files), then you will need to add this functionality yourself by creating a custom route that makes the file available for a limited period of time.
There's a number of ways you could achieve this depending on your use case, but I'd suggest looking into JWT - you can generate a JWT that expires after the appropriate time period, include the JWT in the URL as a query parameter, get the token in the route, and use it to prevent access to that route after the token has expired.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |