开发者

How to save file in ASP.NET MVC from Chrome?

开发者 https://www.devze.com 2023-03-07 05:10 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号