0

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?

Tom Bowen
  • 8,214
  • 4
  • 22
  • 42
  • Could you post the relevant bits of the controller as it looks like it is requiring an authenticated user. – phuzi May 06 '14 at 12:06
  • 1
    Getting the redirect in Fiddler but not the browser suggests that Chrome is sending the auth cookie which Fiddler is not sending. Could you confirm? – phuzi May 06 '14 at 12:07
  • Yes, it looks I needed to send the Auth Cookie and Session ID with it. Chrome was doing it, but not Firefox. – Tom Bowen May 09 '14 at 08:10

2 Answers2

0

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.

Community
  • 1
  • 1
Tom Bowen
  • 8,214
  • 4
  • 22
  • 42
0

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;
    }
}