-1

I have MVC application throwing error 'Access to path XXX denied' while uploading video. Error is not thrown when image is being uploaded.

Any thing wring in my code?

  [HttpPost]
        public ActionResult Index(HttpPostedFileBase video)
        {
            //var httpPostedFile = Request.Files[0];
            var ffMpeg = new NReco.VideoConverter.FFMpegConverter();   
            //ffMpeg.GetVideoThumbnail(Server.MapPath("~/Images"), "video_thumbnail.jpg");           

            var fileName = Path.GetFileName(video.FileName);
            var path = Server.MapPath("~/Images");
            video.SaveAs(path);
            ffMpeg.GetVideoThumbnail(path, "video_thumbnail.jpg");       


            return View();
        }
Jaimin Dave
  • 1,224
  • 10
  • 18
  • Please read [ask] and share your research. The error indicates everything you need to know. You appear to be using an ffmpeg wrapper, where ffmpeg in turn tries to access a path that it's not allowed to, running under the current credentials. Apply the proper permissions to that path, or change it to a path that it _does_ have permissions to. See also [Access to the path is denied](http://stackoverflow.com/questions/4877741/access-to-the-path-is-denied). – CodeCaster Oct 13 '16 at 14:09
  • FYI.. there isnt any issue with permissions. take a look at @Raphaël Althaus answer. It worked perfectly. – Jaimin Dave Oct 14 '16 at 04:12

1 Answers1

0

Well, I would say you have a problem here

video.SaveAs(path);

as path doesn't contains file name (you try to save with the directory as "fileName").

So

var path = Server.MapPath("~/Images");
var fileName = Path.Combine(path, video.FileName);
video.SaveAs(fileName);
Raphaël Althaus
  • 59,727
  • 6
  • 96
  • 122