This is a migrated thread and some comments may be shown as answers.

Passing parameters from Javascript to custom AsyncHandler

9 Answers 284 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Stephan
Top achievements
Rank 1
Stephan asked on 31 Dec 2011, 05:50 PM
Hello,

Is there a way to include parameters from Javascript to be sent to a custom AsyncUploadHandler?

Such parameter could be a folder selected in the page.

I tried to change the url by setting the ctrl.
_handlerUrl attribute from various events. Does not work, the params are removed before they get to the handler.

Creating cookies might work but are no solution in my case.

I am wondering if I am the only person needing such a thing...? Please help!

Thanks,
Stephan


PS: There seems to be a bug when setting a handler url on server side with query string parameters. These parameters are then properly passed to the handler, however, the control adds a "?type=rau". It should of course have added "&type=rau".


9 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 04 Jan 2012, 01:33 PM
Hi Stephan,

 
Unfortunately including parameters from Javascript to a custom  AsyncUploadHandler is not a supported scenario.

As for the  behavior that you described it is a known issue and it is already logged for fixing. 

Hope this will be helpful.

All the best,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Ole Oscar
Top achievements
Rank 1
answered on 12 Apr 2012, 02:09 PM
I am also in need of this.
The file upload scenario is like this.

1. User enter a "entity" (client)
2. The file + the "entity ID" needs to get uploaded to the handler
3. The custom handler analyzes the file based on the file and "entity ID"
4. The custom handler sends the result back to the Web client using custom IAsyncUploadResult.
5. The Web Client picks up the custom IAsyncUploadResult and if more info is needed, ask the user for this.
7. Submit including validation

I was thinking of using a custom AsyncUploadConfiguration object and access it from the Web client side using the OnClientFileUploading event to set the "entity ID". Is it possible ?

Regards
Ole Oscar Johnsen
0
Plamen
Telerik team
answered on 17 Apr 2012, 01:15 PM
Hi Ole,

 
It is not possible to add or change parameters of the uploading file due to security restrictions. If you want to validate the files somehow please refer to this on-line demo.

You can also review our Custom Handler demo which shows how to save images directly to a database, without using temporary folder. 

Hope this information will be helpful.

All the best,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Ole Oscar
Top achievements
Rank 1
answered on 07 May 2012, 02:49 PM
That is really strange.

You have mention that there is a bug in adding parameters to the url and there also exist an old  reply that says this
----------------------------------------------------
Genady Sergeev Genady Sergeev

Posted on Feb 18, 2011 (permalink)

Hi alien9882,

We are currently implementing passing custom parameters in the query string. I believe we will be able to present a solution for the upcoming Q1 release.

As for the configuration object not passing values to the handler, please, update to the latest possible version and try again. There used to be an issue with the custom configuration but we have resolved it. Does the issue persist after the upgrade?

Kind regards,
Genady Sergeev
the Telerik team
-------------------------------------------------------------

That is what I need. Add url parameters to the handler request.

If this is not possible/ not going to be fix very soon I need to find another async file upload solution.
We have been using Telerik for years, and it will be odd to use another supplier for async upload. (I don't know if they exist, but I need to start looking for that soon).

Kindly Regards

Ole Oscar Johnsen
0
Plamen
Telerik team
answered on 10 May 2012, 04:27 PM
Hello Ole,

It seems that I misunderstood your question in the beginning. Please excuse me for that. Passing parameters is currently supported in RadAsyncUpload only from the server side as it is shown in our on-line demo and in the attached project. At the moment such behavior can not be achieved from the client side. It seems that implementing this functionality was postponed due to other features with greater priority and interest from the clients. You can vote for this issue and observe its status in our Pits system -here. Please excuse us once again for this limitation of our control. 

Hope this will explain the issue.

Kind regards,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Ole Oscar
Top achievements
Rank 1
answered on 11 May 2012, 03:23 PM
I have found a work-around for it.
1. The event OnClientFileUploading can't be used to set parameters like cookies since it async and is called during the upload.
So I went back to only return the temporary file name + the standard info from the custom asyncupload handler.
Then I created a new generic handler that uses the info from asyncupload.
This one is called from the OnClientFileUploaded function in javascript using jQuery and I am done.
The new handler needs to know about the asyncupload temporary folder. I am not transferring that to the client.

Here is the javascript code
            function FileUploaded(radAsyncUpload, eventArgs) {
                //document.cookie = "ClientID=; expires=Thu, 01-Jan-70 00:00:01 GMT;";
                //var state = radAsyncUpload.get_clientState();
                var fileInfo = eventArgs.get_fileInfo();
                var clientCombo = $find("<%= Client.ClientID %>");
                var value = clientCombo.get_value();
                CallFileRecognizer({ fileInfo: fileInfo.MetaData, fileName: fileInfo.FileName, clientId: value });
            }

            function FileRecognizerComplete(result) {
                var fileTypeCombo = $find("<%= FileType.ClientID %>");
                if (result != '') {
                    var item = fileTypeCombo.findItemByValue(result);
                    item.select();
                } else {
                    fileTypeCombo.clearSelection();
                }
            }

            function FileRecognizerFailed(result) {
                alert(result.responseText);
            }

            function CallFileRecognizer(data) {
                $.ajax({
                    url: '<%= FileRecognizerHandler %>',
                    contentType: "application/json; charset=utf-8",
                    data: data,
                    success: FileRecognizerComplete,
                    error: FileRecognizerFailed
                });
                return false;
            }

Regards
Ole Oscar Johnsen
0
Plamen
Telerik team
answered on 16 May 2012, 08:56 AM
Hello Ole,

 
Thank you for sharing you workaround with the community and your concern with RadControls.

All the best,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Tony
Top achievements
Rank 1
answered on 17 Apr 2017, 04:24 AM

I am looking for this functionality as well and it seems it is still not available and, 5 years since this post, the bug with ?type=rau is STILL present. Is there any other way than the ajax example at the bottom to address this? I need to pass parameters from the client to the handler.

0
Plamen
Telerik team
answered on 20 Apr 2017, 04:51 AM
Hi,

I am attaching a sample page where a similar scenario is implemented in a scenario where a file can be dragged to one of two folders.

Hope this will be helpful.

Regards,
Plamen
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
AsyncUpload
Asked by
Stephan
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Ole Oscar
Top achievements
Rank 1
Tony
Top achievements
Rank 1
Share this question
or