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:

enter image description here

what wrong here? i'm expecting browser downloads image.

--edit--

enter image description here

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

Popular posts from this blog

php - trouble displaying mysqli database results in correct order -

depending on nth recurrence of job in control M -

sql server - Cannot query correctly (MSSQL - PHP - JSON) -