简体   繁体   English

将.wav文件发送到后端

[英]Sending .wav file to backend

I am currently using RecorderJS and need to send a .wav file to the backend. 我目前正在使用RecorderJS,需要将.wav文件发送到后端。 the API is quite limited in documentation so I am struggling to figure out how to send the .wav file through my axios.post(...). 该API的文档非常有限,因此我正在努力寻找如何通过axios.post(...)发送.wav文件的方法。

I am able to download the .wav file with 我可以使用下载.wav文件

Recorder.download(theblob, 'audio.wav');

this downloads a .wav file which I can play through itunes so it is the right format. 这会下载一个.wav文件,我可以通过它播放它,因此它是正确的格式。 I now need to figure out how to save this in a variable in order to post it through axios. 现在,我需要弄清楚如何将其保存在变量中以便通过axios发布。 Also, what should i use for me headers, .. ect? 另外,我应该为标题使用什么..ect?

Looking for any kind of javascript solution to this. 寻找任何对此的javascript解决方案。 I just need to send the exact downloaded file to my backend. 我只需要将确切下载的文件发送到我的后端即可。 Thanks! 谢谢!

The download method stores the file somewhere on your disk. 下载方法将文件存储在磁盘上的某个位置。 I believe javascript cannot traverse your computer's path and read files for security reasons. 我相信javascript出于安全原因无法遍历计算机的路径并读取文件。 I'm not sure if recorder-js offers storing it in a variable "out of the box", so you may want to get that handled first. 我不确定recorder-js是否提供将其存储在“开箱即用”的变量中,因此您可能要先处理该变量。

For your second part of the question: 对于问题的第二部分:

This should work for posting it to the back-end: 这应该可以将其发布到后端:

let data = new FormData();

data.append('wavfile', file, file.name);

const config = {
  headers: { 'content-type': 'multipart/form-data' }
}
axios.post('/api/recorderfiles', data, config)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM