I'm building an mvc 4 application that makes file uploading. When I get HttpPostedFileBase range, I get streams on them and pass to my business logic layer to save them and bind with database records. This is done without any problems. But when displaying current state of uploading progress comes in, I'm a bit confused. I make a second request while an uploading runs, but it waits for first request to be executed completely.
I know that in same browser client instance (actually same session), my requests are synchronized. But there is a solution that I read about, asynchronous actions.
To try asynchronous actions, I used Stream.CopyToAsync(..) instead of Stream.CopyTo(..). I'm also using Task.Delay(10000) to simulate file uploading progress. Then while asynchronous UploadFile action runs, I invoked synchronous UploadProgress on same browser instance. Result is still waiting for first request to complete. Below is the code I use. Where am I wrong?
Here is async action to upload files;
[HttpPost]
public async Task<ActionResult> Upload(PFileUploadModel files)
{
if (!Session.GetIsLoggedIn())
return RedirectToAction("Login", "User");
var fileRequest = Session.CreateRequest<PAddFileRequest, bool>(); //Creates a business logic request
fileRequest.Files.Add(...);
var result = await Session.HandleRequestAsync(fileRequest); //Handles and executes a business logic request by checking authority
if (result)
return RedirectToAction("List");
return RedirectToError();
}
And upload progress action is simple as below for now :) :
public ActionResult UploadProgress()
{
//var saveProgressRequest = Session.CreateRequest<PSaveFileProgressInfoRequest, PSaveFileProgressInfoResponse>();
//saveProgressRequest.ProgressHandle = progressHandle;
//var response = Session.HandleRequest(saveProgressRequest);
return Content("Test!");
}
Thanks for helping.