Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File upload returns null

I am uploading a file in my ASP.NET MVC application using Uploadify.

Controller:

public ActionResult Upload(HttpPostedFileBase file)
        {           
            List<string> validIDs, invalidIDs;
            if (file.ContentLength > 0)
            { //do something
            }
        }

Uploadify code (in a .ascx file):

$(document).ready(function () {   
    $("#file_upload").uploadify({
        'uploader': '/Scripts/uploadify/uploadify.swf',
        'script': '/XYZ/Upload',
        'cancelImg': '/Scripts/uploadify/cancel.png',
        'fileExt': '*.jpg;*.gif;*.png;*.bmp;*.htm;*.html;*.zip',
        'fileDesc': '*.jpg;*.gif;*.png;*.bmp;*.htm;*.html;*.zip',
        'auto': true,
        'multi': false,
        'sizeLimit': 1048576,   //1 MB
        'buttonText': 'Upload Files'
}
    });
});

The 'file' in the controller action is always returning NULL. What am I missing?

like image 693
GoldenUser Avatar asked Apr 06 '12 20:04

GoldenUser


1 Answers

Replace:

public ActionResult Upload(HttpPostedFileBase file)

with:

public ActionResult Upload(HttpPostedFileBase fileData)

Uploadify uses the fileData name by default. You could change that in the settings if you want like that: fileDataName: 'file'. Take a look at the following post as well.

like image 134
Darin Dimitrov Avatar answered Oct 09 '22 02:10

Darin Dimitrov