Search code examples
asp.net-mvcuploadify

Getting Null value for HttpPostedFileBase with Asp.Net MVC using the latest Uploadifive


So I am trying to implement Uploadifive 1.0 with Asp.NET MVC. Using the debugger mode, I know that the upload action is successfully passed to the Controller and the Server variables are passed as well. However, the HttpPostedFileBase variable fileData is always null. I've looked everywhere on google and couldn't find an answer. I found out that the variable has to be called fileData. That doesn't help though.

Here's part of the view:

<form action="<%: Url.Action("SaveFiles", "File") %>" enctype="multipart/form-data">
    <input type="file" name="file_upload" id="file_upload" />
</form>

<script type="text/javascript">
    (function ($) {
        $(document).ready(function () {
             $('#file_upload').uploadifive({
                 'method': 'post',
                 'uploadScript': 'SaveFiles',
                 'formData': {'path' : 'documents'}
             });
        });
    })(jQuery);
</script>

Here's the controller action:

[HttpPost]
public ActionResult SaveFiles(HttpPostedFileBase fileData)
{
    string uploadFolder = Request.ServerVariables.Get("HTTP_X_PATH");
    if(string.IsNullOrWhiteSpace(uploadFolder))
        return Json(JsonMessageManager.GetFailureMessage("No upload folder was selected"));

    if (fileData != null && fileData.ContentLength > 0)
    {
        var fileName = Path.GetFileName(fileData.FileName);
        var path = Path.Combine(Server.MapPath("~/Content/" + uploadFolder), fileName);
        fileData.SaveAs(path);
        return Json(true);
    }
    return Json(false);            
}

Any pointers or help would be greatly appreciated. I feel lost.


Solution

  • I had the exact same problem with Uploadifive so I posted on the Uploadify forums on an existing thread (probably yours). The author has since posted an update to the Uploadifive plugin which I downloaded and now this works fine for me. In fact, it works exactly like Uploadify used to including additional form data being available in "Request.Forms" and it no longer prepends the "X_" to the additional form data. I would recommend you try the new version and see how you go.

    See the discussion here: http://www.uploadify.com/forum/#/discussion/8223/no-files-attached-to-request