Question

I’m using Jquery Uploadify plugin for Attachments functionality within my ASP.NET MVC 4.5 project.

The plugin works well in IE and Chrome; however users have reported that files are not being uploaded in Firefox, Safari and Opera. Uploadify returns an “Http 302” response, I have scoured the forums and blogs but no luck.

Many of the suggested solutions are for PHP users. Below is the jQuery code. The action method I’m calling does not have an “Authorized” attribute. If anyone has any ideas please let me know.

$('#file_upload').uploadify({
        'overrideEvents': ['onSelectError', 'onDialogClose'],
        'formData': {'id': tid },
        'swf': '/Scripts/uploadify/uploadify.swf',
        'uploader': "/workitem/upload",
                'fileDataName': 'file',
                'fileTypeDesc': 'File',
                'fileTypeExts': '*.jpg; *.jpeg; *.tiff; *.gif; *.bmp; *.png; *.pdf; *.doc; *.docx; *.docm; *.xls; *.xlsx; *.xlsm; *.ppt; *.pptx; *.txt',                
                'auto': false,
                'multi': true,
                'buttonText': 'BROWSE',
                'queueSizeLimit': 10,
                'sizeLimit': 1073741824,
                'uploadLimit': 10,
                'removeCompleted': true,
                'queueID': 'queueContainer',
                'onSelectError': function (a, b, c) {
                    var errorMsg;
                    if (b == -100)
                        errorMsg = 'You have reached the maximum number of files selected.';
                    else if (b == -110)
                        errorMsg = 'The file selected exceeds the file size limit.'
                    else if (b == -120)
                        errorMsg = 'The file selected has zero bytes and cannot be uploaded.'
                    else if (b == -130)
                        errorMsg = 'An invalid file type has been selected.'                    
                },
                'onUploadError': function (file, errorCode, errorMsg, errorString) {                                        
                    alert(errorMsg);
                }    
});

EDIT: On further analysis using Fiddler while browsing with Firefox a 302 request was captured with the location path of “/Account/Login?ReturnUrl=%2fworkitem%2fupload”. That indicates that the user is not authenticated or lost session; however when using Chrome request of HTTP 200 is captured. Does anyone know why this is occurring?

Was it helpful?

Solution

Got the answer from here: Uploadify (Session and authentication) with ASP.NET MVC

You need to send the Auth Cookie and Session ID with it. Chrome was doing it, but not Firefox.

OTHER TIPS

You can have one controller for which you can disable to authentication by adding Attribute at controller level. And you can write upload action for fileupload action.

I guess you only do care about uploading file on some server folder. Please see below code. Which works for me.

[AllowAnonymous]
public class CustomUploadifyController : Controller
{
    [HttpPost]
    public string CaseDocumentUpload(string CaseNumber)
    {
        var file = Request.Files["Filedata"];

        System.IO.Directory.CreateDirectory(Server.MapPath(@"~\Temp\" + CaseNumber));
        string savePath = Server.MapPath(@"~\Temp\" + CaseNumber + @"\" + file.FileName);
        file.SaveAs(savePath);

        return file.FileName;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top