Skip to content Skip to sidebar Skip to footer

Null Parameter When Trying To Pass A Blob To C# Controller

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#.

Solution 1:

Does not rely on a type of C#, rather using this script.

            var length = Request.ContentLength;
            var bytes = new byte[length];
            Request.InputStream.Read(bytes, 0, length);

Solution 2:

Try this:

Client:

<script src="http://code.jquery.com/jquery-1.10.2.min.js" ></script>
<div class='wrapper' >
    <input type='file' class='target' id='targetinput' />
</div>

Javascript:

var xhr = new XMLHttpRequest();
var fd = new FormData();
fd.append("blob.blob", document.getElementById('targetinput').files[0]);
xhr.open("POST", "/Home/SubmitSound", true);
xhr.send(fd);

Server:

[HttpPost]
public ActionResult SubmitSound(SoundBlob blob)
{
        var fileName = Server.MapPath(string.Format("/Content/Sound/{0}.wav", Environment.TickCount));
        blob.blob.SaveAs(fileName);
        return new JsonResult { Data = "Saved successfully" };
}

Perfectly works, i just checked it out


Post a Comment for "Null Parameter When Trying To Pass A Blob To C# Controller"