1. Background
Axios is a Promise-based HTTP library that works in both the browser and Node.js. It beats traditional Ajax in several ways: Promise API, concurrent requests, request/response interceptors, automatic JSON handling, and XSRF protection. It also fits well with MVVM patterns, which is why it’s the go-to HTTP client in Vue.
The problem is that Axios defaults to treating response data as JSON. When you try to download a file, you get the binary stream back, but Axios can’t process it correctly. What you end up with is:
response.statusandresponse.headerslook fine, butresponse.datais garbled- The browser doesn’t trigger a download

2. Using Blob to Handle File Downloads
Since Axios can’t handle file streams directly, we need a workaround. The Blob object — immutable raw data, essentially a container for binary files — does the job. Here’s how to implement it:
1 | // Download file request |
This works, but there’s a catch: if the server returns an error, the Blob will still download a file — just with undefined as the filename. We need to check whether the response is actually an error before proceeding with the download:
1 | // Entry point for file download |