swfupload提示“錯誤302”的解決方法


1、關於圖片上傳控件,flash控件的顯示效果要好一些,本人使用swfupload

2、swfupload上傳控件使用方式詳見文檔 http://www.leeon.me/upload/other/swfupload.html

3、參照文檔說明和官方demo,寫一個小例子是沒有任何問題的,在firefox或者chrome下如碰到302錯誤,錯誤堆棧如下:

SWF DEBUG: SWFUpload Init Complete
SWF DEBUG: 
SWF DEBUG: ----- SWF DEBUG OUTPUT ----
SWF DEBUG: Version:                2.5.0 2010-03-05 Beta 3.2
SWF DEBUG: movieName:              SWFUpload_0
SWF DEBUG: Upload URL:             /iwebshop/index.php?controller=shop&action=goods_imgupload&photo_name=photo_name&showlist=show_list&single=false
SWF DEBUG: File Types String:      *.jpg;*.jpge;*.png;*.gif
SWF DEBUG: Parsed File Types:      jpg,jpge,png,gif
SWF DEBUG: HTTP Success:           0
SWF DEBUG: File Types Description: JPG Images (*.jpg;*.jpge;*.png;*.gif)
SWF DEBUG: File Size Limit:        2097152 bytes
SWF DEBUG: File Upload Limit:      5
SWF DEBUG: File Queue Limit:       5
SWF DEBUG: Post Params:
SWF DEBUG:                         PHPSESSID=feec128121ce54aa04f6b4a249bd5bc9
SWF DEBUG: ----- END SWF DEBUG OUTPUT ----
SWF DEBUG: 
SWF DEBUG: Stage Resize:50 by 21
SWF DEBUG: Event: fileDialogStart : Browsing files. Multi Select. Allowed file types: *.jpg;*.jpge;*.png;*.gif
SWF DEBUG: Select Handler: Received the files selected from the dialog. Processing the file list...
SWF DEBUG: Event: fileQueued : File ID: SWFUpload_0_0
SWF DEBUG: Event: fileDialogComplete : Finished processing selected files. Files selected: 1. Files Queued: 1
SWF DEBUG: StartUpload: First file in queue
SWF DEBUG: Event: uploadStart : File ID: SWFUpload_0_0
SWF DEBUG: StartUpload(): Upload Type: Normal.
SWF DEBUG: Global Post Item: PHPSESSID=feec128121ce54aa04f6b4a249bd5bc9
SWF DEBUG: ReturnUploadStart(): File accepted by startUpload event and readied for standard upload.  Starting upload to /iwebshop/index.php?controller=shop&action=goods_imgupload&photo_name=photo_name&showlist=show_list&single=false for File ID: SWFUpload_0_0
SWF DEBUG: Event: uploadProgress (OPEN): File ID: SWFUpload_0_0 Bytes: 0. Total: 98168
SWF DEBUG: Event: uploadProgress: File ID: SWFUpload_0_0. Bytes: 65536. Total: 98168
SWF DEBUG: Event: uploadProgress: File ID: SWFUpload_0_0. Bytes: 98168. Total: 98168
SWF DEBUG: Event: uploadError: HTTP ERROR : File ID: SWFUpload_0_0. HTTP Status: 302.
EXCEPTION: 
SWF DEBUG: Event: uploadComplete : Upload cycle complete.

紅色文字部分就是返回的錯誤信息,出現此錯誤的原因有以下幾個:

a 、flash上傳圖片時,會另起一個線程上傳,這個線程中沒有cookie,session等會話信息,包括自定義的全局變量,調用上傳的url路徑后台進行處理時,如果后台進行了權限或者登陸校驗就會校驗失敗,后台校驗失敗就會重定向登錄頁面,flash這邊就會報出302錯誤,但是上傳界面不會發生跳轉。

b、如果程序使用了系統框架,一般框架會有過濾器進行權限校驗或者session校驗,對於框架不熟悉的人可能不知道為什么發生302錯誤,也不知道在哪處理過濾,導致無法解決問題,這個需要仔細研究框架了。

c、對於swfupload的demo可以直接部署運行,而不報錯,就是因為接收圖片界面沒有校驗session或者權限。

知道原因后,問題就很好解決,根據MVC項目中的身份驗證節點,如下所示:

    <authentication mode="Forms">
      <forms name="USER_SESSID" loginUrl="~/Admin/Account/Login" protection="All" timeout="10080" path="/" requireSSL="false" slidingExpiration="false" enableCrossAppRedirects="false" cookieless="UseCookies" domain="" />
    </authentication>

在上傳圖片時,需要把session ID Post過去,因為swfupload已經封裝了此功能,在配置swfupload時添加 post_params 屬性即可,實現代碼如下:

post_params: { "ASPSESSID": "@Request.Cookies["USER_SESSID"].Value" },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM