The file that is created by System.IO.File.Create
cannot download like the file created by HttpPostedFileBase.SaveAs
.
My code:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult SaveasMP4(HttpPostedFileBase file)
{
try
{
if (file != null && file.ContentLength > 0)
{
string extension = Path.GetExtension(file.FileName);
var path = Path.Combine(Server.MapPath("~/Data/"), file.FileName);
file.SaveAs(path);
if (!extension.Equals(".mp4"))
{
var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
string tempFileName = path.Substring(0, path.LastIndexOf('.')) + ".mp4";
using (FileStream fileStream = System.IO.File.Create(Path.Combine(Server.MapPath("~/Data/"), tempFileName)))
{
ffMpeg.ConvertMedia(path, fileStream, Format.mp4);
}
if (System.IO.File.Exists(path))
{
System.IO.File.Delete(path);
}
}
}
}
catch (Exception e)
{
ModelState.AddModelError("", e.Message);
return View();
}
return RedirectToAction("Index");
}
if the file is mp4 can be download by using file.SaveAs(path). But if the file is in other format it convert to mp4 successfully by using NReco.VideoConverter and cannot download because it create by System.IO.File.Create(tempFileName) . Just i can download by using ftp.
Is the problem in file access permission?
If it is what should I do in file access permission?