录制音频并发送给Symfony

编程入门 行业动态 更新时间:2024-10-27 08:34:54
本文介绍了录制音频并发送给Symfony的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我只想录制音频并将文件发送到我的控制器. 我正在使用 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

本文发布于:2023-11-25 08:49:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629109.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:音频   Symfony

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!