录制音频并发送给Symfony [英] Record audio and send to Symfony

查看:105
本文介绍了录制音频并发送给Symfony的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想录制音频并将文件发送到我的控制器. 我正在使用 https://addpipe.com/simple-recorderjs-demo/来录制我的音频,就可以了.但是,当我想将我的内容实际发送到Symfony 4项目中的任何内容时,它永远不会收到任何内容.因此,我想出我会手动重制一个插入了音频Blob的表单,但也无法解决问题.

I want to simply record audio and send the file to my controller. I'm using https://addpipe.com/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", "http://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", "http://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

请参阅: https://dev.to/imben1109/html-form-ajax-file-upload-front-end-2klc

或者如果您想使用jquery

or if you want to use jquery

如何使用FormData进行ajax文件上传

这篇关于录制音频并发送给Symfony的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆