How can I generate a URL to view a file (word, pdf, excel) with google docs viewer

0

I'm working with laravel 5.5 and I came across this way of using google docs viewer:

<iframe src="https://docs.google.com/viewer?url=AQUÍ URL DEL DOCUMENTO&embedded=true" width="600" height="780" style="border: none;"></iframe>

My problem is that I do not know how I can generate or obtain a URL for my files, which I keep for the moment locally, inside the storage folder of laravel. I hope you can help me.

    
asked by SlashMaster 05.12.2017 в 20:14
source

2 answers

1

First you must create the route

Route::get('/documento/{nombredelarchivo}/',
        [
          'uses'=>'Controller@generate',
          'as'=>'getDocument'
        ]);

The driver would be like this

public function generate($nombreArchivo)
    {
        $archivo= storage_path($nombreArchivo);
        return response()->download($archivo);
    }

Obviously this is a basic example I would do the validation of the name of the file that exists as well. But you can try this

    
answered by 05.12.2017 в 20:53
0

If you save your files with storage as the target disk, they are saved in the storage / app / public folder, this default folder is not publicly accessible so you have to make a symbolic link, you must run the following command.

php artisan storage: link

If the files you upload manually you can place them in a folder of the public directory. I recommend that you do it in the storage folder of the public directory, if it does not exist, create it, as you would do if you made the symbolic link.

To generate a url is done with these functions:

// without storage, generate an address with http: // {domain} /storage/a.doc url ('storage / a.doc')

// with storage, generate an address to /storage/a.doc Storage :: url ('public / a.doc')

that will generate a file

    
answered by 06.12.2017 в 17:42