Forum

HomeHomeCoreCoreSamples and oth...Samples and oth...Jquery Uploader - Multiple file, no postback!!Jquery Uploader - Multiple file, no postback!!
Previous
 
Next
New Post
2/6/2013 5:30 AM
 
I'm sorry I didn't notice this thread, I am unsure if you still need assistance but are you using the upload handler?  Without it you will recieve that error.  Also, if you do have it, have you tried a single upload?
New Post
2/8/2013 3:26 PM
 

Hi jebrel,

thanks for returning, I followed your instructions but I haven't been able to get it to work.  I do have the handler and I have tried a single file, but get the same error.  Do I need to do anything special to get the handler to work?

Barry

New Post
2/8/2013 5:00 PM
 

I'll try to explain it the best I can.  I currently have it working in several different ways on my portals.  In your case, I would try and get it running with minimal code until you can figure out how it works.  Once I got the base working, it didn't take long to extend it.

 

1. Download and extract package to the ROOT of your site.  This will typicly place the Upload.ashx in the root, and create the uploadify directory.  You can delete the php files as they just came with the package.

2. Open uploadifyOWSConfig.txt, grab txt and import into a new OWS configuration.

3. Open the Upload.ashx and change the directory in which you would like the files to be placed.  I have done SEVERAL changes to this file, the one I provide is the bare bones. 

 

Details of that file are...

 

1. HttpPostedFile file= context.Request.Files["Filedata"]; - This grabs the file from the uploader.

2. int param1 = (Int32.Parse(context.Request["param1"]));  - This grabs the variable you provide, generally this would be an addition to the file name or even to replace it if you choose. I just wanted to show how to send a variable back to the handler in the example.

 

 

I will post what I currently use as a handler, it may help you to see how I have dealt with some issues and how I have sent several variables back to allow for renaming and saving the file to locations defined in OWS.  The first part will be the handler and the second the initialization code.  This also includes some jquery to show messages when the results are returned but it may help you to know how to display returned information in detail..

 

 Handler:

 <%@ WebHandler Language="C#" Class="Upload" %>

using System;
using System.Web;
using System.IO;


public class Upload : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        try
        {
            HttpPostedFile file = context.Request.Files["Filedata"];
                  
            // variables script
            string newFileName = "";
            newFileName = context.Request["param1"].Replace(" ", "");
            
            int fileLen = file.ContentLength;

            // From file stream
            string fileExt = Path.GetExtension(file.FileName);

            // new file name
            string fullFileName = (newFileName + fileExt);
                     
            // root directory of uploaded files  (maybe in the future add ows context for the portals)
            string rootDirectory = Path.Combine(context.Request.PhysicalApplicationPath, "Portals\\0\\OWS_Exports\\");
            
            // get the root folder name from script
            string targetDirectory = Path.Combine(rootDirectory, context.Request["folder"].Replace("/",""));
            
            string returnDirectory = "\\Portals\\0\\OWS_Exports\\" + context.Request["folder"].Replace("/", "");
                
            // Handle sub directories
            if (string.IsNullOrEmpty(context.Request["subdir1"]))
            {
               
            }
            else
            {
                targetDirectory = Path.Combine(targetDirectory, context.Request["subdir1"].Replace(" ", ""));
                returnDirectory = Path.Combine(returnDirectory, context.Request["subdir1"].Replace(" ", ""));
            }

            if (string.IsNullOrEmpty(context.Request["subdir2"]))
            {

            }
            else
            {
                targetDirectory = Path.Combine(targetDirectory, context.Request["subdir2"].Replace(" ", ""));
                returnDirectory = Path.Combine(returnDirectory, context.Request["subdir2"].Replace(" ", ""));
            }
            if (string.IsNullOrEmpty(context.Request["subdir3"]))
            {

            }
            else
            {
                targetDirectory = Path.Combine(targetDirectory, context.Request["subdir3"].Replace(" ", ""));
                returnDirectory = Path.Combine(returnDirectory, context.Request["subdir3"].Replace(" ", ""));
            }
            
            // add extra \\ on end of returndir for path correction
            returnDirectory = returnDirectory + "\\";
                      
            if (!Directory.Exists(targetDirectory))
                Directory.CreateDirectory(targetDirectory);

            // complete renamed file
            string targetFilePath = Path.Combine(targetDirectory, fullFileName);
                  
            // save the file to the file system
            file.SaveAs(targetFilePath);
                     
                     context.Response.ContentType = "text/plain";
            context.Response.StatusCode = 200;
            context.Response.Write("&fileName=" + fullFileName + "&fileLength=" + fileLen + "&fileDirectory=" + returnDirectory.Replace("\\","/") + fullFileName);
 
        }
        catch(Exception ex)
        {
                     context.Response.ContentType = "text/plain";
            context.Response.Write("0");
        }
    }
       public bool IsReusable
       {
              get
              {
              return false;
              }
       }

}

 

The javascript: 

 

$(document).ready(function(){
    $('#file_upload').uploadify({
        'uploader':'/dnn/uploadify/uploadify.swf',
        'script':'UploadRegular.ashx',
        'cancelImg':'/dnn/uploadify/cancel.png',
        'fileDesc': 'PDF Files',
        'fileExt': '*.pdf',
        'sizeLimit': '10485760',
        'buttonText': 'Select File',
        'folder': '/Consumers',
        'onComplete': function(event,queueID, fileObj, response, data) {
        ows.Fetch('[ModuleID,System]',-1,'Action=updateRecord&showSuccessMsg=False','updateForm');
        ows.Fetch('[ModuleID,System]',-1,'Action=AddFile&'+ response,'attachmentSQ');
        $('#divUploaderMessage').hide('fast');
        },
        'multi': false,
        'onSelect' : function(){
        $('#file_upload').uploadifySettings('scriptData', {'param1': "SAS_F" + $('#fileID').val() + "_" + $('#frmLastName').val() + "-" + $('#frmFirstName').val() + "_[COALESCE,Date,System,{0:MM-dd-yyyy}]",
        'subdir1': $('#frmLastName').val() + "_" + $('#frmFirstName').val() + "_" + $('#frmSSN1').val().substring(7,11), 'subdir2':"SASForms", 'subdir3':"" });
        },
        'onOpen': function(event,ID,fileObj) {$('#divUploaderMessage').show('fast').html('<table cellpadding="0" cellspacing="0" border="0"><tr><td id="tdMessageLeft"><img src="images/wait32.png"></td><td id="tdMessageRight">You must wait for the file upload to complete before proceeding.</td><tr><table>');
        }

    });

}); 

 

 

Previous
 
Next
HomeHomeCoreCoreSamples and oth...Samples and oth...Jquery Uploader - Multiple file, no postback!!Jquery Uploader - Multiple file, no postback!!


 

New York, NY • Baltimore, MD • Vienna, VA • St. Louis, MO • Seattle, WA • 410.327.0007 • info@R2Integrated.com

Bookmark & Share Bookmark and Share