突然之前显示的图片停止显示在页面上并检查文件夹 * 发现当我单击它们时图像不显示。调试我的代码,我发现注释行导致了它。下面的代码是否无论如何都在操纵流?
public ActionResult UploadPhoto(UserPhotoUploadModel photoFileModel)
{
HttpPostedFileBase photoFile = photoFileModel.PhotoFile;
string uploadPath = Server.MapPath("~/Content/users/photos");
string autoFileName = String.Format("{0}_{1}", Guid.NewGuid().ToString(), filename);
string fileDestName = Path.Combine(uploadPath, autoFileName);
//Starting from here is where the issue lies
Stream imgStream = photoFile.InputStream;
using (imgStream)
{
Image img = Bitmap.FromStream(imgStream);
int width = img.Width;
int height = img.Height;
if (width > 100 || height > 100)
{
ModelState.AddModelError("PhotoFile", "Photo dimension should be 100 by 100 or less");
return View(photoFileModel);
}
}
//the issue ends here
photoFile.SaveAs(fileDestName);
return RedirectToAction("Profile", new {id = loggedinUser.ProviderUserKey});
}
保存的文件具有正确的图像扩展名,例如 JPG。我正在使用流来确定上传图像的尺寸。
注释部分是导致此问题的原因。如何在输入流完好无损的情况下做到这一点?
谢谢。