2 years ago

Issue with Laravel Response download and Axios post

Posted 2 years ago by VinayKesharwani

I am using Laravel 5.5 with Vue.js 2.4. This SPA uses Axios library for request. I was trying to post Axios request and on successful operation, one file was supposed to be downloaded.

Here is my axios post request'/api/download/file',{id:id})
    .then(response => {
    }).catch(error => {

My controller method is as following:

public function download(){
    $download_path = storage_path('app/'.$id.'.zip');

    $headers = ['Content-Type: application/zip','Content-Disposition: attachment'];

    return response()->download($download_path, $id.'.zip',$headers);

On request, file dialogue is not opening nor the file is downloaded. However the contents are sent back to the success response.

How file can be downloaded using Axios post & Laravel response()->download() method? Any help will be appreciated. Thanks in advance.

Please sign in or create an account to participate in this conversation.