So I am referring to Saving WAV File Recorded in Chrome to Server to save a blob to my server. However, I cannot translate this PHP sentence in to 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");
?>
Here is what I've tried so far
View
var fd = new FormData();
fd.append("that_random_filename.wav", blob);
xhr.open("POST", "SubmitSound", true);
xhr.send(fd);
View model
public class SoundBlob
{
public string key { get; set; }
public HttpPostedFileBase blob { get; set; } // I tried byte[] and string too
}
Controller
[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" };
}
Both key
and blob
of SoundBlob
is null! How can I fix it?