@sadiss Use an access token like in a password reset link. You can inspect that code and get an idea of what to do.
User specified download link
I have a table which have following fields
id | post_id | sender | receiver | filename | created_at | updated_at
1 | 1 | 1 | 2 | file.jpg | date | date
files are store in
storage/sender/postid/file.jpg which means it is in storage_direcotry/1/1/file.jpg
what i want to create a download link which only allow receiver to download the file any other user or guest try to access the link will end up seeing 404 or any other error.
Please help
@sadiss Hey.
You can make the request go through your app and determine whether the request is valid or not. What I would do is expose an endpoint to download files, maybe something like:
example.com/downloads/{hash}
Now you are going to associate any file in your database with some kind of a hash. You would then create a controller to respond to that URI and determine whether the user should have access to the file or not:
public function show($hash)
{
// Perform the authorization
abort_unless(optional(auth()->user())->canDownload($hash), 404);
return response()->file($pathToFile);
}
Please or to participate in this conversation.