Answer the question
In order to leave comments, you need to log in
How to get file on ASP.NET MVC sent via XmlHttpRequest?
There is a code that sends a file to "/Home/Test"
var fileE = document.getElementById("fileAvatar");
fileE.onchange = function ()
{
var xhr = new XMLHttpRequest();
xhr.open("POST", "/Home/Test");
xhr.send(this.files[0]);
}
public JsonResult Test(HttpPostedFileBase fileAvatar)
{
return Json(new {status="OK" });
}
Answer the question
In order to leave comments, you need to log in
try this
public JsonResult UploadPure()
{
string fileName = Request.Headers["X-File-Name"];
string fileType = Request.Headers["X-File-Type"];
int fileSize = int.Parse(Request.Headers["X-File-Size"]);
System.IO.Stream fileContent = Request.InputStream;
System.IO.FileStream fileStream = System.IO.File.Create(Server.MapPath("~/") + fileName);
fileContent.Seek(0, System.IO.SeekOrigin.Begin);
fileContent.CopyTo(fileStream);
fileStream.Dispose();
return Json("Uploaded files");
}
it's work for me , for more info: www.agileinfoways.com/technical-expertise/ms-techn...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question