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

Complete validation before performing DELETE when multiple = false

3 Answers 44 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Grant
Top achievements
Rank 2
Veteran
Iron
Grant asked on 06 Jan 2020, 01:49 PM

Hi, 

To expand on my title a bit, I have a Upload widget which doesnt allow multiple files, and validates that uploaded documents are pdf's under 4Mb.

The problem is that when a new file is uploaded to replace the existing one, the Upload widget will make a call to delete the existing document, ONLY THEN will it validate the new one. How can I trigger the validation before the delete? This would prevent my users from inadvertently deleting the previous document, if the new one is not valid.

Thanks,
Grant

3 Answers, 1 is accepted

Sort by
0
Petar
Telerik team
answered on 08 Jan 2020, 11:53 AM

Hi Grant,

Can you check this Dojo example and let me know if the proposed maxFileSize and allowedExtensions validation resolve the reported issue?

With the linked demo you should be able to validate the file before sending it to the server. 

Regards,
Petar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Grant
Top achievements
Rank 2
Veteran
Iron
answered on 08 Jan 2020, 12:20 PM

Hi Petar, 

Thanks for getting back to me. As I mentioned, I already have validation in place for new files, that part is not the problem. Please see the following Use Case describing the current behaviour of the Upload widget:

Req: There are no documents in the upload widget
1) [User] Clicks 'Select' and chooses a document to upload
2) [Widget] Triggers a POST on the 'saveUrl' for the new document to be uploaded (it's successful)
3) [User] Clicks 'Select' again and chooses a different document to upload
4) [Widget] Triggers a POST on the 'removeUrl', effectively deleting the document because "multiple=false"
5) [Widget] Validates the new document against the specified rules and uploads is if validation passes

My problem is that step 4 is happening before step 5. The existing document is being deleted BEFORE the new one is validated.I need the widget to follow the following use case:

3) [User] Clicks 'Select' again and chooses a different document to upload
4) [Widget] Validates the new document against the specified rules
4.1) Validation passes
4.1.1) [Widget] Triggers a POST on the 'removeUrl', effectively deleting the document
4.1.1) [Widget] Triggers a POST on the 'saveUrl', uploading the new document
4.2) Validation fails
4.2.1) Alert user

I hope I've managed to convey what Im trying to do. Unfortunately I cannot Dojo it as the KendoUI demo's fail in the Dojo environment.

Thanks and Kind Regards,
Grant

0
Petar
Telerik team
answered on 10 Jan 2020, 08:46 AM

Hi Grant,

To achieve the desired functionality, the upload event could be used to check the size of the file that is about to be uploaded. If the size is above 4 Mb the upload can be prevented. 

Here is a modified version of the previous Dojo that demonstrates the mentioned above approach. 

Let me know if the proposed solution resolves the issue on your end.

Regards,
Petar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Upload
Asked by
Grant
Top achievements
Rank 2
Veteran
Iron
Answers by
Petar
Telerik team
Grant
Top achievements
Rank 2
Veteran
Iron
Share this question
or