2011-01-14 3 views
0

uploadify를 사용하여 ASP.NET MVC 웹 응용 프로그램에서 간단한 파일 업로드를 시도하고 있습니다. IE8에서는 잘 작동합니다. Firefox와 Chrome에서는 컨트롤러 작업에 게시하지 않는 것 같습니다. 누군가 내가 잘못하고있는 것을 찾도록 도와 줄 수 있습니까? 나는 JQuery와 1.4.1 자체가 swfobject 2.2을 포함 uploadify 2.1.4의 현재 버전의 내용을 포함하고Firefox 또는 Chrome에서 저에게 직장을 올리지 못하는 이유는 무엇입니까?

<input type="file" id="file_upload" name="FileData" /> 

:

여기 내 HTML입니다. 여기

내 스크립트입니다 :

$ (함수() {

$("#file_upload").uploadify({ 
    'uploader': '/Scripts/uploadify.swf', 
    'script':  '/Uploads/UploadFile', 
    'cancelImg': '/Content/Images/cancel.png', 
    'auto':  true, 
    'multi':  false, 
    'folder':  '/uploads', 

    onComplete : function() { 
    alert("complete"); 
    }, 

    onOpen : function() { 
    alert("open"); 
    }, 

    onError : function (event, id, fileObj, errorObj) { 
    alert("error: " + errorObj.info); 
    } 

}); 

});

그리고 여기 내 컨트롤러 액션의 크롬과 파이어 폭스에서

public string UploadFile(HttpPostedFileBase FileData) 
{ 
    // do stuff with the file 
} 

, 나는 구글에서 찾을 수있는 것과 매우 비밀 보인다 "오류 # 2038"메시지를 얻을. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

+0

및 오류 메시지를받을 수 있나요이 내가 진행하는 방법이다? –

+0

오류 메시지는 onError 콜백의 errorObj에 있습니다. –

답변

3

상황이 시도 :

  1. 귀하의 컨트롤러 액션이 ActionResult,
  2. Fiddler를 설치하고 내부적으로 어떻게 볼 수 없습니다 문자열을 반환해야한다 (당신은 HTTP 요청/응답 프레임과 가능한 오류가 발생합니다) . 그런 다음 여러 브라우저 간의 결과를 비교하여 변경 사항이 있는지 확인하십시오. 크리스 농부처럼
+1

고마워 ... 나는 이것을보기 위해 더 일찍 피들러를 사용하려고 노력했지만, 나는 그 포스트를 컨트롤러에 다시는 알리지 못했다. 로컬 호스트 요청을 기록하는 피들러를 읽는 방법을 읽은 후에는 ASP.NET 세션이 표준 브라우저 기반 요청보다 플래시 요청에서 다르므로이 작업이 인증 작업이라는 것이 분명해졌습니다. 감사! –

+0

어떻게 해결 했습니까? 내 문제는 IE와 작동하지만 Firefox와 Chrome에서는 작동하지 않습니다. –

+0

해결 방법에 대한 해결책을 게시 할 수 있습니까? 비슷한 문제가있는 모든 사용자에게 유용 할 것입니다. – ZVenue

0

것은 해결하기 위해 (당신은 Fiddler2에이를 볼 수 있습니다) 세션, 쿠키 .ASPXAUTH (또는 다른 세션 쿠키가) 크롬과 파이어 폭스에 전송되지 않습니다 플래시 요청에 다른 말했다 이 문제는 uploadData와 함께 "scriptData"를 사용할 수 있습니다.

string scriptDataValues = string.Empty; 
      if (Request.Cookies != null && Request.Cookies.Length > 0) 
      { 
       // Generate scriptData 
       scriptDataValues = ", 'scriptData' : {"; 
       string[] formatedData = new string[Request.Cookies.Length]; 
       int i = 0; 
       foreach (HttpCookie cookie in cookies) 
       { 
        // Format cookie to scriptData name:value 
        formatedData[i] = string.Format("\"{0}\":\"{1}\"", cookie.Name, cookie.Value); 
        i++; 
       } 
       // separate all formated cookies with comma 
       scriptDataValues += string.Join(",", formatedData); 
       scriptDataValues += "}"; 
      } 
    // add scriptData to your js script 
    string yourScript = "<script type=\"text/javascript\"> 
$(document).ready(function() { $('#file_upload').uploadify({ 
     'uploader' : '/uploadify/uploadify.swf', 
     'script'  : '/uploadify/uploadify.php', 
     'cancelImg' : '/uploadify/cancel.png', 
     'folder'  : '/uploads' 
     " + scriptDataValues + " 
    }); }); 
</script>" 

을 그리고 컨트롤러에있는 당신의 행동 :

당신의 uploadify JS이 추가 :

[HttpPost] 
     public ActionResult UploadProductImage(HttpPostedFileBase image, FormCollection collec) 
     { 
      Partner partner = null; 
      if (!string.IsNullOrEmpty(collec[".ASPXAUTH"])) 
      { 
       // Get cookie in POST values 
       FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(collec[".ASPXAUTH"]); 
       if (ticket.Expiration > DateTime.Now) 
       { 
        // Authenticated user, upload the file and return url 
       } 
      } 
     return this.Content(string.Empty); 
     } 
관련 문제