在 MVC 中上传视频时拒绝访问路径 XXX
Access to the path XXX is denied while uploading video in MVC
我在上传视频时遇到 MVC 应用程序抛出错误 'Access to path XXX denied'。图片上传时不报错
我的代码有什么问题吗?
[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();
}
嗯,我会说你这里有问题
video.SaveAs(path);
因为路径不包含文件名(您尝试将目录保存为 "fileName")。
所以
var path = Server.MapPath("~/Images");
var fileName = Path.Combine(path, video.FileName);
video.SaveAs(fileName);
我在上传视频时遇到 MVC 应用程序抛出错误 'Access to path XXX denied'。图片上传时不报错
我的代码有什么问题吗?
[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();
}
嗯,我会说你这里有问题
video.SaveAs(path);
因为路径不包含文件名(您尝试将目录保存为 "fileName")。
所以
var path = Server.MapPath("~/Images");
var fileName = Path.Combine(path, video.FileName);
video.SaveAs(fileName);