录音,保存斑点文件服务器 - C#的mvc [英] Voice Recorder, Saving Blob file to server - C# , Mvc
问题描述
我需要在我的工作,也是记录的声音,必须在后面听一个项目录音机。
该项目由C#和asp.net mvc的开发。
I need a voice recorder in a project which I am working on and also the recorded voices must be listened later. That Project developed by c# and asp.net mvc.
http://demos.subinsb.com/jquery/voice/
我使用的是记录系统,在上面的链接。当您点击下载它给你一个文件.WAV格式。
它下载到你的电脑,但我想将其保存到服务器上。
I am using a recorder system in that link above. When you click Download it gives you a file .wav format. It is downloaded to your computer but I want to save it to server.
本项目的源$ C $ CS可用下面的链接。
This project’s source codes is available below the link.
http://demos.subinsb.com/down。 ?PHP的ID = S / rvx90xq1xtpak3xc647n和放大器;类= 31
我调查jQuery的codeS:
当您点击下载
I investigate jquery codes: When you click Download
$(document).on("click", "#download:not(.disabled)", function () {
$.voice.export(function (url) {
$("<a href='" + url + "'download='MyRecording.wav'></a>")[0].click();
}, "URL");
restore(); });
这是工作在此功能。在功能上的网址parametre回应你,链接为
It is working in this function. Url parametre in function respond you that link as
blob:http%3A//localhost%3A1875/146432b2-8b1b-4eef-8d77-1fdbc8fc74c9
当你走在播放WAV文件ADRES是工作,但在SRC STIL的球员有这个codebelow
When you go that adres in player wav file is working but src in player stil has this code below
blob:http%3A//localhost%3A1875/146432b2-8b1b-4eef-8d77-1fdbc8fc74c9
问:
我怎样才能声音文件保存到服务器上。我不能在这个网站上,总体达到互联网从问题的任何解决方案:)
How I can save sound file to server. I can not reach any solution from the questions in this web site and generally in internet :)
1 - ?哪些parametre我要送与jQuery阿贾克斯到控制器
1 – Which parametre I have to send to controller with Jquery Ajax?
2 - 如何给parametre WAV或MP3格式转换在控制器侧
2 – How to convert that parametre to wav or mp3 format in controller side?
感谢哟这么多从现在开始:)
Thank yo so much from now :)
推荐答案
我去recorder.js因为我想定制 - 我只需要回调,我可以用我自己的UI使用
I went with recorder.js because I wanted the customization — I only needed callbacks I can use with my own UI.
要开始使用后,这里是有关的JavaScript code:
To start with the post, here is the relevant JavaScript code:
Recorder.js上传功能
Recorder.js upload 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);
}
});
}
在服务器端,这是pretty简单。你把一个正常的控制器动作与HttpPostedFileBase参数去与文件输入。另一种方式是使用Request.Files。然而,在我的情况,我用数据模型来接收输入。
On the server side, it’s pretty simple. You take a normal controller action with an HttpPostedFileBase parameter to go with the file input. Another way is to use Request.Files. However, in my case, I used a data model to receive the input.
VoicePassage类
VoicePassage class
public class VoicePassage
{
public string Title { get; set; }
public string FileName { get; set; }
public HttpPostedFileBase Recording { get; set; }
}
如何保存文件的简单化下来的版本。这一次是真正简单化了。你应该在你的数据模型,使用标准或定制ValidateAttribute /秒进行验证输入。应该有一个自定义[Mime类型(音频/ WAV)]属性数据模型中的某个地方,也
The dumbed-down version of how to save the file. This one is really dumbed down. You should be validating input using standard or custom ValidateAttribute/s on your data models. There should be a custom [MimeType("audio/wav")] attribute in the data model somewhere, too.
如何保存文件简单化下来的版本
Dumbed-down version of how to save the file
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。回到客户端,你可以简单的处理结果,并采取行动,喜欢它添加到列表或显示错误。
The Recorder.upload() function issues an AJAX request to the server, so it makes sense to return a JsonResult rather than an ActionResult. Back on the client-side, you can simply process the result and take action, like append it to a list or display an error.
这篇关于录音,保存斑点文件服务器 - C#的mvc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!