如何发送POST请求从客户端java脚本发送BLOB数据并通过MVC控制器接收?

时间:2014-11-23 15:55:13

标签: javascript asp.net asp.net-mvc

我目前的代码:

Javascript

function pushFunc() {

    mediaRecorder.requestData();
    console.log(mediaRecorder.state);

    mediaRecorder.ondataavailable = function (e) {
        console.log("data size: ", e.data.size);
        var encodeData = new Blob([e.data], { type: 'video/mp4' });
        postBlobData(encodeData);
    }

}


function postBlobData(blob) {

    var formData = new FormData();

    formData.append("blobContent", blob);

    var request = new XMLHttpRequest();
    request.open("POST", "/Device/Upload");
    request.send(formData);
}

ASP.NET

**File: DeviceController.cs**

[HttpPost]
        public string Upload(HttpPostedFileBase blobContent)
        {
            ...
            // return View();
        }

Java脚本代码从Media记录器获取blob并尝试将其发布到Controller。

  1. 我是否应该以我应该的方式抓住并发布blob?

  2. 是否应该使用HttpPostedFileBase在服务器端接收发布请求?

  3. Fiddler截屏#1

    enter image description here

    Fiddler截屏#2

    enter image description here

    Fiddler截屏#3

    enter image description here

0 个答案:

没有答案