php - Laravel file download -
i've got method in laravel 5.3 application returns file this:
public function show(file $file) { $path = storage_path('app/' . $file->getpath()); return response()->download($path, $file->name); }
i'm making request in vue.js this:
show (file) { vue.http.get('/api/file/' + file); }
the result this:
what wrong here? i'm expecting browser downloads image.
--edit--
when dd($path);
result: /home/vagrant/code/forum/storage/app/users/3/messages/xreamzk7vheayngkj8qkgvvsrubagcdeze.png
the route in api.php
:
route::get('/file/{file}', 'file\filecontroller@show');
when add web.php it's working. need acces through api!
you can this:
public function show(file $file) { $path = storage_path('app/' . $file->getpath()); $headers = array( 'content-type: image/png', ); return response()->download($path, $file->name, $headers); }
hope helps!
Comments
Post a Comment