0

I'm using Laravel with React js . i want to download files so i use return response()->download($pathToFile) where pathToFile is located in public dir.my url is guarded by auth middleware. i tried solution at Force Download via Ajax and PHP but doesn't work.

In another hand i use axios to send ajax request to get file, I get response headers like thatresponse header

and get encoded response like enter image description here

How i force browser to download file?

Eslam Tahoon
  • 2,205
  • 4
  • 15
  • 21
  • Possible duplicate of [Force Download via Ajax and PHP](https://stackoverflow.com/questions/14774282/force-download-via-ajax-and-php) –  Jun 09 '17 at 17:03
  • You cannot "force" a browser to download anything. It must be accepted by the end user. –  Jun 17 '17 at 05:57

1 Answers1

2

I was using axios so i added responseType: 'blob' to request header then used filesave or responseType: 'blob' or react-file-download to download file

axios.get(url, {responseType: 'blob'})
    .then((res) => {
        FileDownload(res.data, filename);
    });
Eslam Tahoon
  • 2,205
  • 4
  • 15
  • 21