Uploadify 3.1和MVC 3.0 HTTP 500错误

时间:2012-05-11 07:14:00

标签: asp.net-mvc asp.net-mvc-3 uploadify

在uploadify中上传文件时,我一直遇到500错误。不确定我可能做错了什么......

jQuery(document).ready(function () {
    jQuery("#file_upload").uploadify({
        'swf': '@Url.Content("~/Content/uploadify/uploadify.swf")',
        'buttonText': 'Browse Files',
        'uploader': '@Url.Action("upload", "upload")',
        'debug': true,
        'fileObjName': 'file',
        // 'scriptData': { 'fname':$("#fname").val(), 'fname2':fname},
        'fileSizeLimit': '38000000',
        'multi': true,
        'auto': true,
       'onUploadError' : function(file, errorCode, errorMsg, errorString) {
           alert('The file ' + file.name + ' could not be uploaded: ' + errorString)
       }, 
        onAllComplete: function (event, queueID, fileObj, response, data) {
            alert(response);

        }
    });
}); 

//控制器:

 [HttpPost]
         public ActionResult Upload(HttpPostedFileBase file)
        {



            var fileName = Path.GetFileName(file.FileName); 
            file.SaveAs("D:\\inetpub\\wwwroot\\RTDOTNETMEMBER\\audio\\songs\\mp3\\" + fileName);
            return Content(fileName);

        }

调试文件:

---SWFUpload Instance Info---
Version: 2.2.0 2009-03-25
Movie Name: SWFUpload_0
Settings:
    upload_url:               /upload/upload
    flash_url:                /Content/uploadify/uploadify.swf?preventswfcaching=1336720242632
    use_query_string:         false
    requeue_on_error:         false
    http_success:             
    assume_success_timeout:   30
    file_post_name:           file
    post_params:              [object Object]
    file_types:               *.*
    file_types_description:   All Files
    file_size_limit:          38000000
    file_upload_limit:        0
    file_queue_limit:         999
    debug:                    true
    prevent_swf_caching:      true
    button_placeholder_id:    file_upload
    button_placeholder:       Not Set
    button_image_url:         /Song/
    button_width:             120
    button_height:            30
    button_text:              
    button_text_style:        color: #000000; font-size: 16pt;
    button_text_top_padding:  0
    button_text_left_padding: 0
    button_action:            -110
    button_disabled:          false
    custom_settings:          [object Object]
Event Handlers:
    swfupload_loaded_handler assigned:  false
    file_dialog_start_handler assigned: true
    file_queued_handler assigned:       true
    file_queue_error_handler assigned:  true
    upload_start_handler assigned:      true
    upload_progress_handler assigned:   true
    upload_error_handler assigned:      true
    upload_success_handler assigned:    true
    upload_complete_handler assigned:   true
    debug_handler assigned:             true

SWF DEBUG: SWFUpload Init Complete
SWF DEBUG: 
SWF DEBUG: ----- SWF DEBUG OUTPUT ----
SWF DEBUG: Build Number:           SWFUPLOAD 2.2.0
SWF DEBUG: movieName:              SWFUpload_0
SWF DEBUG: Upload URL:             /upload/upload
SWF DEBUG: File Types String:      *.*
SWF DEBUG: Parsed File Types:      
SWF DEBUG: HTTP Success:           0
SWF DEBUG: File Types Description: All Files (*.*)
SWF DEBUG: File Size Limit:        38912000000 bytes
SWF DEBUG: File Upload Limit:      0
SWF DEBUG: File Queue Limit:       999
SWF DEBUG: Post Params:
SWF DEBUG: ----- END SWF DEBUG OUTPUT ----
SWF DEBUG: 
SWF DEBUG: Event: fileDialogStart : Browsing files. Multi Select. Allowed file types: *.*
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: ReturnUploadStart(): File accepted by startUpload event and readied for upload.  Starting upload to /upload/upload for File ID: SWFUpload_0_0
SWF DEBUG: Event: uploadProgress (OPEN): File ID: SWFUpload_0_0
SWF DEBUG: Event: uploadProgress: File ID: SWFUpload_0_0. Bytes: 3545865. Total: 3545865
SWF DEBUG: Event: uploadError: HTTP ERROR : File ID: SWFUpload_0_0. HTTP Status: 500.
SWF DEBUG: Event: uploadComplete : Upload cycle complete.
SWF DEBUG: Event: AssumeSuccess: 30 passed without server response

1 个答案:

答案 0 :(得分:3)

添加以下开关:

fileDataName: 'file'

此外,您似乎混淆了swfuploader参数。试试这样:

jQuery(document).ready(function () {
    jQuery("#file_upload").uploadify({
        uploader: '@Url.Content("~/Content/uploadify/uploadify.swf")',
        script: '@Url.Action("upload", "upload")',
        fileDataName: 'file',
        sizeLimit: 38000000,
        cancelImg: '@Url.Content("~/Content/uploadify/cancel.png")',
        auto: true,
        debug: true,
        onError: function() {
            alert('some error occurred. Sorry');
        },
        onComplete: function (event, queueId, fileObj, response, data) {
            alert(response);
        }
    });
}); 

并在服务器上:

[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
    if (file != null && file.ContentLength > 0)
    {
        // TODO: storing uploaded files to the App_Data folder on the server. 
        // Adjust this location to fit your requirements
        var appData = Server.MapPath("~/app_data");
        var filename = Path.Combine(appData, Path.GetFileName(file.FileName));
        file.SaveAs(filename);
    }
    return Json(true);
}