2011-02-03 5 views
10

저는 Valums Ajax 업 로더를 사용하고 있습니다. 모든이 코드를 모질라에서 잘 작동 :MVC Valums Ajax 업 로더 - IE가 스트림을 request.InputStream에 보내지 않습니다.

보기 :

var button = $('#fileUpload')[0]; 
var uploader = new qq.FileUploader({ 
    element: button, 
    allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'], 
    sizeLimit: 2147483647, // max size 
    action: '/Admin/Home/Upload', 
    multiple: false 
}); 

컨트롤러 :

MVC3 Valums Ajax File Upload

,369 :이 게시물에 대답했다

public ActionResult Upload(string qqfile) 
{ 
    var stream = Request.InputStream; 
    var buffer = new byte[stream.Length]; 
    stream.Read(buffer, 0, buffer.Length); 

    var path = Server.MapPath("~/App_Data"); 
    var file = Path.Combine(path, qqfile); 
    File.WriteAllBytes(file, buffer); 

    // TODO: Return whatever the upload control expects as response 
} 

그러나 이것은 IE에서 작동하지 않습니다. 나는이를 발견했다하지만 난 그것을 구현하는 방법을 알아낼 수 없습니다 :

IE가에서 HttpPostedFileBase을 통해 대신 을 얻을 ... "request.InputStream"의 입력 스트림을 스트림을 전송하지 않습니다 Request.Files [] 모음 또한

,이 사람이 그것을 어떻게이 여기에 표시하지만 난 내 프로젝트에 대한 변경하는 방법을 잘 모르겠어요 :

Valum file upload - Works in Chrome but not IE, Image img = Image.FromStream(Request.InputStream)

//This works with IE 
HttpPostedFileBase httpPostedFileBase = Request.Files[0] 

as HttpPostedFileBase;

이 내용을 파악할 수 없습니다. 도와주세요! 감사합니다.

답변

16

알아 냈습니다. 이것은 IE와 mozilla에서 작동합니다.

[HttpPost] 
     public ActionResult FileUpload(string qqfile) 
     { 
      var path = @"C:\\Temp\\100\\"; 
      var file = string.Empty; 

      try 
      { 
       var stream = Request.InputStream; 
       if (String.IsNullOrEmpty(Request["qqfile"])) 
       { 
        // IE 
        HttpPostedFileBase postedFile = Request.Files[0]; 
        stream = postedFile.InputStream; 
        file = Path.Combine(path, System.IO.Path.GetFileName(Request.Files[0].FileName)); 
       } 
       else 
       { 
        //Webkit, Mozilla 
        file = Path.Combine(path, qqfile); 
       } 

       var buffer = new byte[stream.Length]; 
       stream.Read(buffer, 0, buffer.Length); 
       System.IO.File.WriteAllBytes(file, buffer); 
      } 
      catch (Exception ex) 
      { 
       return Json(new { success = false, message = ex.Message }, "application/json"); 
      } 

      return Json(new { success = true }, "text/html"); 
     } 
+0

네입니다! 너는 방금 백만 시간을 구 했어. 고마워. –

+0

훌륭한 사람 !!!! +10 –

+1

PHP 용으로 어떻게 복제 할 수 있습니까? – dallen

0

셰인의 솔루션이 작동하지만 IE의 어쨌든 요청 [ "qqfile"]이 설정되어있는 것으로 보입니다. 내가 fileuploader의 업데이트 된 버전을 사용하고 있기 때문에 이것이 확실한 지 모르지만 IE에서 작동하도록 "if"문을 수정했습니다 (요청에 업로드 된 파일이 있는지 확인).

if (Request.Files.Count > 0) { 
    //ie 
} else { 
    //webkit and mozilla 
} 

다음은 전체 조각

[HttpPost] 
public ActionResult FileUpload(string qqfile) 
{ 
    var path = @"C:\\Temp\\100\\"; 
    var file = string.Empty; 

    try 
    { 
     var stream = Request.InputStream; 
     if (Request.Files.Count > 0) 
     { 
      // IE 
      HttpPostedFileBase postedFile = Request.Files[0]; 
      stream = postedFile.InputStream; 
      file = Path.Combine(path, System.IO.Path.GetFileName(Request.Files[0].FileName)); 
     } 
     else 
     { 
      //Webkit, Mozilla 
      file = Path.Combine(path, qqfile); 
     } 

     var buffer = new byte[stream.Length]; 
     stream.Read(buffer, 0, buffer.Length); 
     System.IO.File.WriteAllBytes(file, buffer); 
    } 
    catch (Exception ex) 
    { 
     return Json(new { success = false, message = ex.Message }, "application/json"); 
    } 

    return Json(new { success = true }, "text/html"); 
} 
관련 문제