갑자기 이전에 표시되었던 사진이 페이지에 표시되지 않고 폴더를 확인하면 * 이미지를 클릭 할 때 표시되지 않습니다. 내 코드 디버깅 주석이 달린 행이 그 원인을 발견했습니다. 어쨌든 스트림을 조작하는 코드가 있었습니까?fileupload에서 결과를 어떻게 든 조작하는 스트림 사용
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. 스트림을 사용하여 업로드 된 이미지의 크기를 결정하고 있습니다.
주석 처리 된 부분이이 문제의 원인입니다. 입력 스트림을 그대로 유지하려면 어떻게해야합니까?
감사합니다. 코드는 방법에서 종료이 줄을 명중 할 때
return View(photoFileModel);
:
주석이 달린 부분이 없으면 이미지는 완벽하게 저장되었지만 추가 할 때 이미지는 비어 있거나 실제 이미지가 아니므로 표시되지 않습니다. 브라우저. 나는'using' 블록이'photoFile.SaveAs (fileDestName)'이 호출되기 전에 스트림을 지웠다고 생각한다. 왜냐하면'photoFile.SaveAs (fileDestName)'을'using'으로 옮기는 것이 가능하기 때문입니다. – codingbiz
무엇이 문제입니까? –
분명히 쓰레기/아무것도 파일에 저장되지 않기 때문에 스트림이 변조되는 것을 어떻게 방지 할 수 있습니까? 파일은 유효한 이미지 파일이 아닌 위치에 있지만 – codingbiz