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

re-upload possible?

2 Answers 55 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Tayger
Top achievements
Rank 1
Iron
Tayger asked on 02 Mar 2018, 08:45 PM

Hello there

Just got the message that some of you have holidays. Wish all those guys a good time. You are all doing a great job at Telerik!

My question: I'm using the kendoUpload widget that is working well. I'm trying to keep customers logged in if they have set that in their settings. So when the session ran out (after a certain time of user nactivity) I'm checking every server side action. If the session ran out I recreate it and send the user action again from client (now with reactivated session). That works everywhere well and the user won't realise what just happened. There is only one case I don't know how to treat the same way: kendoUpload

When the user is doing a file upload (single file mode) and there is no more serverside  session I call the upload function again but then there are no (to be uploaded) image information anymore. After thinking about this behaviour is obvious to me since I'm calling the function programmatically there are no values set  anymore.

So I wonder if it's possible to do the upload programmatically inside the upload widget (or to catch the upload data) to do the upload again? I'm using the success event  of the KendoUpload widget to get/check the upload status from the server:

a) Session still active, upload worked well

b) Session timeout, restart the upload again (programmatically)

It's not a big thing if there is no solution for that problem. So I'm asking if there is a way I could do the upload again (programmatically) with the data/file the user initially tried to upload?

Greetings

2 Answers, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 06 Mar 2018, 10:59 AM
Hello Tayger,

Typically, with upload input, there is no possible way to add a stream value so that it appears as a file is selected. This is an user interaction field and as it serves the purpose of uploading a file from the client to the server, there is no programmatic access to the interact with the stream added by the user. Or create a new one even if previously the user has added. Generally, there are security reasons for that to be not doable. 

If you are using the async option, however, you can fake it up. You can interact with the files collection of the Upload so that after session timeout the Upload appears as if the file is uploaded successfully.

If you are using the classic mode of the Kendo Upload what I can suggest you is to implement some additional UI element to show to the client that the file is uploaded succesfully and hide the Kendo Upload widget. 

Regards,
Ianko
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Tayger
Top achievements
Rank 1
Iron
answered on 15 Mar 2018, 04:58 PM

Hello Ianko

Thank you for your answer. I thought that there is no easy/obvious question. I also really get your point how to fake it. But while reading your answer another idea came up to me. I've tried that out and it works: I check for existing session in the upload event like this:

        $("#uploadfile").kendoUpload({
            async: {
                saveUrl: "../php/uploadimage.php"
            },
...
            upload: function (e) {
                // Make sure session is active
                $.ajax({
                    type: 'POST',
                    url: '../php/sessionrefresh.php',
                    dataType: 'json',
                    async: false,
                    success: function(s) {
                        if (s.state !== 'OK') {
                            window.location.href = 'https://.../sessionend.php';
                        }
                    }
                });
            },
...

 

In the upload event of the upload widget the sessionrefresh.php function tries to reactivate the session (if not still active) and returns OK if session is still active or could be reactivated. In this case proceed with the image upload. If the session couldn't be reactivated it heads to sessionend.php telling the user he is logged out.

I don't know if this is the best solution to solve this problem but it works!

 

 

Tags
Upload
Asked by
Tayger
Top achievements
Rank 1
Iron
Answers by
Ianko
Telerik team
Tayger
Top achievements
Rank 1
Iron
Share this question
or