0

Good day!

In my project, I have an Axios request which returns a raw wav data inside response.data. How do I create a wav file from that raw data and then download it into the browser?

Raw wav data

When I visit the URL with browser, it automatically downloads the wav file. But when I use Axios request with that URL, the response.data looks like the image above. How do I download that into a wav file?

Thank you in advance!

ADyson
  • 57,178
  • 14
  • 51
  • 63
codezero11
  • 427
  • 1
  • 5
  • 10
  • There are examples online already of how to download files from an Ajax request - you need some additional steps...but is there any reason you decided to use Ajax/Axios in this scenario? JavaScript can be told to navigate directly to a new URL to download it. You can make it open as if it's in a new tab, if you're worried about preserving the current page. Most likely you can do without the added complexity that AJAX causes in this scenario – ADyson Feb 04 '21 at 08:37
  • Hi! Thank you for the reply. I used Axios because I need to access the URL via POST method and I need to pass some parameters.. – codezero11 Feb 04 '21 at 08:42
  • You said it works if you do it directly in the browser. That's a GET. So why do you need a POST for this one? What's the difference? Parameters could be passed in the query string, if a script needs to process them before allowing the download – ADyson Feb 04 '21 at 09:10
  • But if you want to continue down this road, does this answer your question? [Download binary file with Axios](https://stackoverflow.com/questions/49040247/download-binary-file-with-axios) – ADyson Feb 04 '21 at 09:11

0 Answers0