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

Set UID in initial file list

5 Answers 621 Views
Upload
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 24 Apr 2017, 03:30 PM

How do I set the uid for files in the initial file list options for the upload widget?  

When I upload files the guid is auto generated and easily available in the upload event via e.files[0].uid

I have saved this information in the database along with the file and can repopulate the widget with previously uploaded files, but not set the uid, a new, different one is generated.  I would like to set it so I can use the existing uid when a user clicks remove on a previously uploaded file and I can delete it from the database.

The initial files array seems not to support it, is there another way?

http://docs.telerik.com/kendo-ui/api/javascript/ui/upload#configuration-files

5 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 25 Apr 2017, 07:39 AM
Hello William,

As you have noticed the uid of an uploaded file is generated automatically. Setting the uid initially, for example uid: "123", in the files array is not supported, i.e. the widget rcognizes only name, size and extension values set through files.
The uid of a currently selected file (a file added through the files configuration option is considered selected) can be set after the file list is populated, as shown below:
var upload = $("#upload").data("kendoUpload");
var files = upload1.getFiles();
files[0].uid = "123"

Regards,
Ivan Danchev
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.
0
Christopher
Top achievements
Rank 1
answered on 22 Aug 2018, 03:15 PM

I know this post is a bit old, but this does not appear to work with the MVC widget.  This returns an undefined variable

$("#[replace_with_the_name_of_the_widget]").data("kendoUpload");

I found another post that mentioned updating the template to add an attribute. (https://www.telerik.com/forums/adding-an-id-to-selected-items)  I have not tried this just yet, so I am not 100% certain this will work either. 

Honestly, this seems to be a key feature missing from the widget.  While I understand the widget wants to own the uid, this could cause a collision since the Guid is being generated on the client.  A better option is to allow the server to manage the generation of the Uid and have it configurable to allow this.

This would handle two issues:

1) When you want to load existing files, you can set the key identifier that was generated when the file was uploaded.  This would make the removal of the files in an edit screen a little easier.

2) You allow the server to manage the Uid which lowers the possibility of a collision associated with the Guid.  In some cases, a developer may want to use a different identifier, for instance, a crypto-random-string.  This would allow for them to do this.  In some industries, this is a requirement.  In my case, the Uid that is generated is only a temporary identifier and it is replaced when the file is moved to the location where it will be persisted.

For now, I hope the template works, but I highly recommend adding this to the backlog.

~Cheers

0
Christopher
Top achievements
Rank 1
answered on 22 Aug 2018, 03:24 PM

Correction: It wasn't working because there is a type in the code block provided.  For those who run into this in the future, here is an updated code block:

var upload = $("#replace_with_the_name_defined").data("kendoUpload");
var files = upload.getFiles();
files[0].uid = "123"

 

I still believe this should be part of the widget.

~Cheers

0
Christopher
Top achievements
Rank 1
answered on 22 Aug 2018, 03:25 PM

The reason it was showing up is because the code example had a type.  Here is an updated code block for Ivan's example:

var upload = $("#upload").data("kendoUpload");
var files = upload.getFiles();
files[0].uid = "123"

 

I still believe this should be configurable in the widget.

~Cheers

0
Ivan Danchev
Telerik team
answered on 24 Aug 2018, 10:38 AM
Hello,

Indeed there was a typo in the code snippet I posted. Thank you for pointing that out. As for your idea about making this configuration available in the widget you can log it in our Feedback Portal. Highly demanded features often get approved by the team for future implementation.

Regards,
Ivan Danchev
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.
Cristian
Top achievements
Rank 1
commented on 06 Jan 2022, 12:35 PM

why it's not possible to set at the initial files object? because it's hard to modify many files uploaded, and where should be it add?

I have the same problem, I try load the files from the database were I saved the UID but it 's lost when I fill the files object.

Martin
Telerik team
commented on 10 Jan 2022, 12:01 PM

As the feature is not supported, I would recommend using some of the approaches discussed here or in the another mentioned forum thread. If you are still having difficulties, kindly provide a runnable example where I can observe them and help you further.
Tags
Upload
Asked by
William
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Christopher
Top achievements
Rank 1
Share this question
or