1
한 번에 여러 이미지를 업로드 할 수있는 asp.net mvc 응용 프로그램이 있는데 제대로 작동하지만 원본에서 축소판 이미지를 만드는 데 문제가 있습니다. 여기 업로드 된 이미지의 썸네일 만들기
코드입니다 : 그러니까 기본적으로file.SaveAs(path);
가 작동하고 실제로 이미지를 저장하지만, 마지막 줄은
[HttpPost]
public ActionResult SaveUploadedFile()
{
bool isSavedSuccessfully = true;
string fName = "";
try
{
foreach (string fileName in Request.Files)
{
HttpPostedFileBase file = Request.Files[fileName];
fName = file.FileName;
if (file != null && file.ContentLength > 0)
{
var originalDirectory = new DirectoryInfo(string.Format("{0}Images", Server.MapPath(@"\")));
string pathString = Path.Combine(originalDirectory.ToString(), "Gallery");
string pathString2 = Path.Combine(originalDirectory.ToString(), "Gallery\\Thumbs");
//var fileName1 = Path.GetFileName(file.FileName);
bool exists = Directory.Exists(pathString);
bool exists2 = Directory.Exists(pathString2);
if (!exists)
Directory.CreateDirectory(pathString);
if (!exists2)
Directory.CreateDirectory(pathString2);
var path = string.Format("{0}\\{1}", pathString, file.FileName);
file.SaveAs(path);
//WebImage img = new WebImage(file.InputStream);
WebImage img = new WebImage(fileName);
//if (img.Width > 1000)
img.Resize(100, 100);
img.Save(pathString2);
}
}
}
catch (Exception ex)
{
isSavedSuccessfully = false;
}
if (isSavedSuccessfully)
{
return Json(new { Message = fName });
}
else
{
return Json(new { Message = "Error in saving file" });
}
}
내가 만들고 엄지 손가락을 저장하려고하지만 그것이 작동하지 않는 라인 (내가 할 후 그래도 전에 생성 된 Thumbs
폴더 가져 오기).
나는 또한 Error in saving file
응답을 얻지 만 그 이유는 엄지 손가락을 만들고 저장하려고하기 때문입니다. 제거하지 않으면 실제로 볼 수있는 실제 오류를 반환하는 방법을 모릅니다. 무슨 잘못이야.
어쩌면 img.Save (pathString2)'에서 pathString2''때문이다 ' "갤러리 \\ 엄지 손가락"값을 가지고 있으며, 당신이 패치 파일 이름을 추가하는 것을 잊지. 'catch'에 중단 점을 설정하고 예외가 던져지는 것을보십시오. – Sylwekqaz
그것은 null입니다. 왜 내가 여기에 할당 한 전체 경로 대신에 그 값을 가질 수 있을까? string pathString2 = Path.Combine (originalDirectory.ToString(), "Gallery \\ Thumbs"); ? 그리고 나는 "패치에 파일 이름을 추가하는 것을 잊어 버린다"는 것을 이해하지 못합니다. 예제를 제공해주십시오. – frc
pathstring2에 완전하고 정확한 경로가 있습니다. 방금 중단 점을 확인했습니다. – frc