1
FileUploader Pass GUID to FileUploader_Uploaded event
Question asked by Naveen - 2/19/2025 at 1:50 PM
Answered
I'm using FileUploader to upload files, and I need to store all uploaded files in a uniquely generated GUID folder per session. Since the Metadata property is not available in FileUploader, I'm trying to pass this GUID dynamically for each upload request. I initially stored the GUID in a session, but I realized this could cause issues if a user opens multiple tabs. I attempted to pass the GUID using a hidden field and attach it via JavaScript in the onFileUploading event, but I need to ensure it gets properly sent and securely validated on the server in the FileUploader_Uploaded event. How can I reliably pass this GUID so that each uploaded file is stored in the correct session-based folder while preventing users from modifying the folder ID or exploiting the upload process?

1 Reply

Reply to Thread
1
Cem Alacayir Replied
Employee Post Marked As Answer
We have a solution for this:

Version 9.3.4 - March 3, 2025

  • Added: FileUploader.CustomParameters property which gets or sets the custom parameters for this uploader instance,
    to send along with the upload queue. These custom parameters can be retrieved in server-side events,
    for example to take an action depending on the parameters.

    The key of the dictionary is of type.
    The value the dictionary is of type which means you can set any value that is JSON serializable.
    For values, it's recommended to use primitive types like , , etc.

    C#
    //Set some custom parameters for this uploader instance, to send along with the upload queue.
    var fileUploader2 = new FileUploader
    {
        CustomParameters = new Dictionary<string, object>
        {
            {"MyParam1", "test"},
            {"MyParam2", true},
            {"MyParam3", 50}
        }
    };
    
    //Or set them like this:
    fileUploader.CustomParameters.Add("MyParam1", "test");
    fileUploader.CustomParameters.Add("MyParam2", true);
    fileUploader.CustomParameters.Add("MyParam3", 50);
    
    
    //In server-side events, you can examine your custom parameters via e.Queue.CustomParameters property
    //and take an action depending on them.
    fileUploader.Uploading += (sender, e) =>
    {
        //Casting can cause problems, e.g. (int)e.Queue.CustomParameters["MyParam3"]
        //especially for int types as when JsonDeserializer is deserializing numbers from a dictionary,
        //it treats them as long (int64).
        //So use methods of Convert to avoid casting problems.
    
        var myParam1 = Convert.ToString(e.Queue.CustomParameters["MyParam1"]);
        var myParam2 = Convert.ToBoolean(e.Queue.CustomParameters["MyParam2"]);
        var myParam3 = Convert.ToInt32(e.Queue.CustomParameters["MyParam3"]);
    };

Reply to Thread