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
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

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

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

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
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
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.