我找到了几个答案(例如这里),但它们似乎没有解决我的问题。
var result = {
command: 'exportWAV',
type: type
};
$.ajax({
url: 'SubmitSound',
type: 'Post',
data: JSON.stringify(result),
contentType: 'application/json; charset=utf-8',
success: function (msg) {
alert(msg);
}
});
后端代码
[HttpPost]
public ActionResult SubmitSound(string blob)
{
// Create the new, empty data file.
string fileName = AppDomain.CurrentDomain.BaseDirectory + "/Content/Sound/" + Environment.TickCount + ".wav";
FileStream fs = new FileStream(fileName, FileMode.CreateNew);
BinaryWriter w = new BinaryWriter(fs);
w.Write(blob);
w.Close();
fs.Close();
return new JsonResult() { Data = "Saved successfully" };
}
result
不为空,因为this.postMessage = result;
将文件发送回客户端进行下载。w.Write(blob)
一直抱怨blob
不可能null
。
我怎样才能让它工作?感谢你并致以真诚的问候