skip to Main Content

I want to embed a pdf from storage into a view/iframe. The storage is private and I can’t permanently store the files on public folder.

Is there any way to accomplish this? Now the users need to see the pdf directly on page instead of downloading it.

I thought copying the file to public and delete it after being served, it’s a valid approach?

Thanks for any guidance!

2

Answers


  1. Maybe you can try using temporary URLs. Check docs here https://laravel.com/docs/11.x/filesystem#temporary-urls

    If you need a more robust logic, add to that new endpoint a simple check for user authentication before serving the file.

    Login or Signup to reply.
  2. Try using temporary urls given by laravel like so:

    use IlluminateSupportFacadesStorage;
    
    $url = Storage::temporaryUrl(
        'file.jpg', // Replace with your file.
        now()->addMinutes(5),
        [
            'ResponseContentType' => 'application/octet-stream', // Add any headers as you need.
            'ResponseContentDisposition' => 'attachment; filename=file2.jpg',
        ]
    );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search