我只想录制音频并将文件发送到我的控制器. 我正在使用 addpipe/simple-recorderjs-demo/来录制我的音频,就可以了.但是,当我想将我的内容实际发送到Symfony 4项目中的任何内容时,它永远不会收到任何内容.因此,我想出我会手动重制一个插入了音频Blob的表单,但也无法解决问题.
I want to simply record audio and send the file to my controller. I'm using addpipe/simple-recorderjs-demo/ to record my audio, and this is working just fine. But when i want to actually send my to anything in my Symfony 4 project, it never receives anything. So i figured i manually remake a form with the audio blob inserted, but does not work out either.
任何想法如何实现这一目标?任何正确方向的线索都将很棒!
Any ideas how to make this happen? Any leads in the correct direction would be great!
我尝试将音频文件简单地插入到现有的表单中,但是由于安全原因,现在不再允许这样做.
I've tried simply inserting the audio file into a existing form, but because of security reasons this is not allowed anymore.
var formElement = document.querySelector("form"); var formData = new FormData(formElement); var request = new XMLHttpRequest(); request.open("POST", "127.0.0.1/index.php/processaudio"); formData.set("form_file", blob, 'file'); request.send(formData);推荐答案
尝试一下:
var formElement = document.querySelector("form"); var formData = new FormData(formElement); var request = new XMLHttpRequest(); request.open("POST", "127.0.0.1/index.php/processaudio"); var fileSelect = document.getElementById("fileSelect"); if(fileSelect.files && fileSelect.files.length == 1){ var file = fileSelect.files[0] formData.set("file", file , file.name); request.send(formData); }fileSelect是输入文件的ID
fileSelect is id of input file
请参阅: dev.to/imben1109/html-form-ajax-file-upload-front-end-2klc
或者如果您想使用jquery
or if you want to use jquery
如何使用FormData进行ajax文件上传
更多推荐
录制音频并发送给Symfony
发布评论