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

how to change the saveUrl in onUpload

5 Answers 1815 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Tom Ridenour
Top achievements
Rank 1
Tom Ridenour asked on 10 Jan 2012, 06:19 PM
When a file is uploaded I need to change the saveUrl to add parameters for a post. This code has no effect on the saveUrl. 

function onUpload(e) {
                    var upload = e.files;                   
                    
                    if (upload[0].extension != ".xml") {
                        alert("Only Xml files can be uploaded");
                        e.preventDefault();
                    }
                    else {
                        e.data = { fileName: upload[0].name };
                        kendoConsole.log("Upload :: " + getFileInfo(e));
                    }


                    //get the options and add to the Url
                    var option1 = $("#actions").val();
                    var postUrl = "PostViewData.svc/FileUpload/" + option1;
                    this.options.async.saveUrl = postUrl;
                }
How can the saveUrl be modified?

$("#files").kendoUpload({
                        async: {
                        saveUrl: "PostViewData.svc/FileUpload",                            
                            autoUpload: false
                        },
                        multiple: false,
           showFileList: true,
                        select: onSelect,
                        upload: onUpload,
                        success: onSuccess,
                        error: onError,
                        complete: onComplete,
                        cancel: onCancel,
                        remove: onRemove,
                        localization : { uploadSelectedFiles: "Upload"}
                    });

This is similar to adding a query string... saveUrl is already committed by the time the event onUploadFires?

5 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 13 Jan 2012, 09:31 AM
Hello,

The saveUrl is indeed committed by the time the upload event fires. That said, you can add fields to the request by setting the data field of the event:
function onUpload(e) {
    e.data = { actions: $("#actions").val() };
}

Is this solution applicable for your scenario?

Regards,
Tsvetomir Tsonev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Tom Ridenour
Top achievements
Rank 1
answered on 13 Jan 2012, 03:33 PM
In this situation that will work because I have control of the REST service. But I think there maybe a way to modify the saveUrl when the user selects an option.

For example:
//dropdown

$(

"#actions").kendoDropDownList({

 

    change: onChange,

    dataSource: data,

    index: 0

});

//the onChange event

 

function

 

onChange() {

 

 

    var option1 = $("#actions").val();

 

}

I am new to jquery/javascript, I come from a Silverlight background. I think in the onChange event I can select the (#files)  kendoUploadControl and modify the saveUrl but I am not sure how to do that... any help is appreciated.

0
T. Tsonev
Telerik team
answered on 16 Jan 2012, 04:41 PM
Hi,

Actually, the current implementation takes the saveUrl immediately after the file is selected. Changing it will have effect for newly selected files.

There's no need to handle the dropdownlist change event, you can access its value in the upload handler, as illustrated earlier.

I hope this helps.

All the best,
Tsvetomir Tsonev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Michael
Top achievements
Rank 2
answered on 20 Feb 2014, 06:25 PM
Hi Tsvetomir,

I'm trying to use this solution to pass a file count [not batch upload, the actual count of items contained by the control at the time an action is completed successfully], but i'm unsure how we need to process the "e.data" in the controller action.

Can you provide a short code snippet that demonstrates how to access anything we put in e.data on the server side. We are using MVC / C#.

Thanks in advance for any help you can offer!
Michael
0
Michael
Top achievements
Rank 2
answered on 20 Feb 2014, 09:00 PM
Hi all, we have coded a working solution that meets our needs. We did try to pass the necessary parameters in the "data" object, but while these were seen in the headers, they were not picked up on the controller action side of things. Here is what we're doing:

var repl = "count=" + window.count;
if (e.operation == "upload") {
    window.count++;
}
else if (e.operation == "remove") {
    window.count--;
}                       
$("#files").data("kendoUpload").options.async.saveUrl = $("#files").data("kendoUpload").options.async.saveUrl.replace(repl, "count=" + window.count);

this is essentially the answer to the original post. YES, you can rewrite the saveUrl parameter. In our case, we're doing so in the onSuccess event when e.response.status == "OK", indicating that we've got a successful upload or delete.

the above code is being used to do server side validation to prevent users from uploading more than the maximum number of files.

cheers,
Michael
Tags
Upload
Asked by
Tom Ridenour
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Tom Ridenour
Top achievements
Rank 1
Michael
Top achievements
Rank 2
Share this question
or