【发布时间】:2013-09-23 03:03:05
【问题描述】:
所以我指的是 Saving WAV File Recorded in Chrome to Server 将 blob 保存到我的服务器。但是,我无法将这个 PHP 语句翻译成 C#。
<?php
// get the temporary name that PHP gave to the uploaded file
$tmp_filename=$_FILES["that_random_filename.wav"]["tmp_name"];
// rename the temporary file (because PHP deletes the file as soon as it's done with it)
rename($tmp_filename,"/tmp/uploaded_audio.wav");
?>
这是我目前尝试过的
查看
var fd = new FormData();
fd.append("that_random_filename.wav", blob);
xhr.open("POST", "SubmitSound", true);
xhr.send(fd);
查看模型
public class SoundBlob
{
public string key { get; set; }
public HttpPostedFileBase blob { get; set; } // I tried byte[] and string too
}
控制器
[HttpPost]
public ActionResult SubmitSound(SoundBlob 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);
blob.blob.SaveAs(blob.key);
w.Close();
fs.Close();
return new JsonResult() { Data = "Saved successfully" };
}
key 和 blob 的 SoundBlob 均为空!我该如何解决?
【问题讨论】:
标签: c# javascript php asp.net-mvc