录音机,将Blob文件保存到服务器 – C#,Mvc

我需要在我正在处理的项目中使用录音机,并且必须稍后收听录制的声音。 该项目由c#和asp.net mvc开发。

http://demos.subinsb.com/jquery/voice/

我正在上面的链接中使用录像机系统。 单击“下载”时,将为您提供文件.wav格式。 它被下载到您的计算机,但我想将其保存到服务器。

该项目的源代码可在链接下方找到。

http://demos.subinsb.com/down.php?id=s/rvx90xq1xtpak3xc647n&class=31

我调查jquery代码:当你单击下载

$(document).on("click", "#download:not(.disabled)", function () { $.voice.export(function (url) { $("")[0].click(); }, "URL"); restore(); }); 

它正在使用此function。 函数中的url参数响应链接为

 blob:http%3A//localhost%3A1875/146432b2-8b1b-4eef-8d77-1fdbc8fc74c9 

当你在播放器中播放时,wav文件正在工作,但播放器stil中的src下面有这个代码

 blob:http%3A//localhost%3A1875/146432b2-8b1b-4eef-8d77-1fdbc8fc74c9 

题:

如何将声音文件保存到服务器。 我无法从本网站的问题和一般在互联网上找到任何解决方案:)

1 – 我必须使用Jquery Ajax向控制器发送哪些参数?

2 – 如何在控制器端将该参数转换为wav或mp3格式?

从现在开始,非常感谢你们:)

我选择了recorder.js,因为我想要自定义 – 我只需要回调,我可以使用自己的UI。

从post开始,这里是相关的JavaScript代码:

Recorder.js上传function

 doUpload: function(title, filename) { Recorder.upload({ method: "POST", url: "@Url.Action("Upload", "Recordings")", audioParam: "Recording", // Name for the audio data parameter params: { // Additional parameters need to be an object "Title": title, "FileName": filename }, success: function(response) { console.log(response); } }); } 

在服务器端,它非常简单。 您可以使用HttpPostedFileBase参数执行常规控制器操作以使用文件输入。 另一种方法是使用Request.Files。 但是,就我而言,我使用数据模型来接收输入。

VoicePassage类

 public class VoicePassage { public string Title { get; set; } public string FileName { get; set; } public HttpPostedFileBase Recording { get; set; } } 

如何保存文件的愚蠢版本。 这个真的很愚蠢。 您应该在数据模型上使用标准或自定义ValidateAttribute / svalidation输入。 数据模型中也应该有自定义[MimeType(“audio / wav”)]属性。

Dumbed-down版本如何保存文件

 public JsonResult Upload(VoicePassage passage) { // Validate the input // ... // ... // Save the file string path = Server.MapPath(string.Format("~/Recordings/{0}.wav", passage.FileName)); passage.Recording.SaveAs(path); return Json(new { Success: true }); } 

Recorder.upload()函数向服务器发出AJAX请求,因此返回JsonResult而不是ActionResult是有意义的。 回到客户端,您可以简单地处理结果并采取行动,例如将其附加到列表或显示错误。