Setting spaces image as private to public but available via application
Hi.
I wish my users to be able to upload images to spaces and make sure they're not accessible to anyone outside of the application.
I would have thought it would be as simple as
Storage::get (with secret key) - and access the image... But it doesn't seem to be so easy.
You have to use a route and a controller to retrieve the images.
Here is the idea, but it depends on what you are passing to the controller : id, image name, image slug, ... and my example assumes you have an Image model. In the response you need to give the file url in the file method.
Route::get('image/{id}', ImageController::class);
...
// ImageController
public function __invoke($id)
{
$image = Image::find($id);
return response()->file($image->url);
}
UPDATED => no url as parameter but an id or a name or a slug, ...
@webleyson You didn't say that your images aren't on the server and I could guess. You need to be precise when you create a post and give all needed informations.
Thus my answer was about what I thought.
But what I shared with you works fine too, but is better appropriated for images on the server.