2011-11-22 1 views
0

그래,이 작업을 중단하지 않고 많은 검색을 수행했습니다. 이미지를 데이터베이스에서 가져올 때 이미지를 표시 할 수 없습니다. 수동으로 핸들러 링크로 이동하려고하면 "이미지 [이미지]에 오류가 있기 때문에 표시 할 수 없습니다"라는 메시지가 나타납니다. 나는 이전의 데이터베이스에서 오래된 이미지를 가지고 있었고 처음에는 올바르게 표시했다. 하지만 지금은 이미지를 업데이 트하면 그것을 보려고 할 때이 오류가 발생합니다.HttpHandler [Image]에 오류가 포함되어 있기 때문에 표시 할 수 없습니다.

업로드 코드. 여기

if (fileuploadImage.HasFile) 
     { 
      if (IsValidImage(fileuploadImage)) 
      { 
       int length = fileuploadImage.PostedFile.ContentLength; 
       byte[] imgbyte = new byte[length]; 
       HttpPostedFile img = fileuploadImage.PostedFile; 
       img.InputStream.Read(imgbyte, 0, length); 

       if (mainImage == null) 
       { 
        ProfileImage image = new ProfileImage(); 
        image.ImageName = txtImageName.Text; 
        image.ImageData = imgbyte; 
        image.ImageType = img.ContentType; 
        image.MainImage = true; 
        image.PersonID = personID; 

        if (image.CreateImage() <= 0) 
        { 
         SetError("There was an error uploading this image."); 
        } 
       } 
       else 
       { 
        mainImage.ImageName = txtImageName.Text; 
        mainImage.ImageType = img.ContentType; 
        mainImage.ImageData = imgbyte; 
        mainImage.MainImage = true; 
        mainImage.PersonID = personID; 

        if (!mainImage.UpdateImage()) 
        { 
         SetError("There was an error uploading this image."); 
        } 
       } 
      } 
      else 
      { 
       SetError("Not a valid image type."); 
      } 

내 이미지 핸들러 :

public class ImageHandler : IHttpHandler 
{ 
    public bool IsReusable 
    { 
     get 
     { 
      return false; 
     } 
    } 

    public void ProcessRequest(HttpContext context) 
    { 
     int imageid = Parser.GetInt(context.Request.QueryString["ImID"]); 
     ProfileImage image = new ProfileImage(Parser.GetInt(imageid)); 

     context.Response.ContentType = image.ImageType; 
     context.Response.Clear(); 
     context.Response.BinaryWrite(image.ImageData); 
     context.Response.End(); 
    } 

그리고 이것은 내가 그것을 전화 했어 어떻게? "~/ImageHandler.ashx IMID ="+ Parser.GetString (image.ImageID)

저는 이것을 저장하기 위해 SQL Server에 데이터 형식 Image를 사용하고 있습니다.

편집 : 나는 또한 발견

그 나는 그것을 말하고 밖으로 erroring한다) context.Response.end (주위 시도 캐치를 넣으면 "코드를 평가할 수 없습니다를 기본 프레임 때문에 ..."

답변

0

내 문제가 발견되었습니다. 실제 파일의 헤더를 검사하여 유효한지 확인했습니다. 어떻게 든 그것은 데이터를 변경하고 그것을 나쁘게 만들고 있었다.

+0

아마 MemoryStream이 원래 위치로 재설정되지 않았습니까? –