Set UID in initial file list

6 posts, 0 answers
  1. William
    William avatar
    1 posts
    Member since:
    Apr 2017

    Posted 24 Apr 2017 Link to this post

    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

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    2061 posts

    Posted 25 Apr 2017 Link to this post

    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.
  3. Christopher
    Christopher avatar
    3 posts
    Member since:
    May 2015

    Posted 22 Aug 2018 Link to this post

    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

  4. Christopher
    Christopher avatar
    3 posts
    Member since:
    May 2015

    Posted 22 Aug 2018 in reply to Christopher Link to this post

    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

  5. Christopher
    Christopher avatar
    3 posts
    Member since:
    May 2015

    Posted 22 Aug 2018 in reply to Christopher Link to this post

    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

  6. Ivan Danchev
    Admin
    Ivan Danchev avatar
    2061 posts

    Posted 24 Aug 2018 Link to this post

    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.
Back to Top