i am trying to save a file from chrome using AjaxSubmit. i got the problem that Chrome send the file in octet format and i am unable to check that if it is really image or anything else.
when i try to call
HttpPostedFileBase file
file.InputStream
inputstream caused error in chrome that Parameter is not valid.
how i开发者_C百科 can save them in asp.net c#
I use this in my view: <input type="file" id="deploymentPackage" name="deploymentPackage" />
And in my controller, I do this:
public ActionResult AddRelease(ApplicationReleaseViewModel appRelease, HttpPostedFileBase deploymentPackage)
{
if (ModelState.IsValid)
{
ApplicationRelease dto = new ApplicationRelease();
appRelease.UpdateDto(dto);
using (StreamReader sr = new StreamReader(deploymentPackage.InputStream))
{
dto.DeploymentPackage = new byte[deploymentPackage.InputStream.Length];
deploymentPackage.InputStream.Read(dto.DeploymentPackage, 0, dto.DeploymentPackage.Length);
}
this.ApplicationService.AddApplicationRelease(dto);
return RedirectToAction("Index", new { ActionPerformed = "ApplicationReleaseAdded", Name = appRelease.Name.CutToMaxLength(50).UrlEncode() });
}
else
{
ViewBag.PostAction = "AddRelease";
return View("EditRelease", appRelease);
}
}
UPDATE: Look at this link, if you can't abstract yourself from "my" code.
http://www.codeproject.com/KB/aspnet/Implementing_HTTP_File_Up.aspx
精彩评论