I've used a couple of async file upload solutions. I think
this one[
^] is pretty nice and easy to implement using MVC.
Add the following code to your controller :
[Authorize]
[HttpPost]
public ActionResult Upload()
{
bool continueUpload = true;
var dyn = new { success=false, error = "Unknown error while uploading" };
string uploadPath = ConfigurationManager.AppSettings[AppSettingKeys.UPLOAD_REPOSITORY_SETTING];
if (!string.IsNullOrEmpty(uploadPath))
{
string fileLocation = Path.Combine(uploadPath, Session.SessionID + "_" + Request.QueryString["qqfile"]);
using (MemoryStream memStream = new MemoryStream())
{
try
{
Request.InputStream.CopyTo(memStream);
}
catch (HttpException hex)
{
continueUpload = false;
dyn = new { success = false, error = "File is too large" };
}
if (continueUpload)
{
memStream.Seek(0, SeekOrigin.Begin);
using (FileStream fstrm = new FileStream(fileLocation, FileMode.Append, FileAccess.Write, FileShare.None))
{
memStream.CopyTo(fstrm);
dyn = new { success = true, error = string.Empty };
}
}
}
}
return Json(dyn, "text/html");
}
This will handle your uploaded file(s). As you can see, the code above is not quite neat, so it needs a couple of tweaks, however it will work using the javascript library.
Hope it helps, good luck!
Eduard