Rename file before upload

8 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    4 posts
    Member since:
    May 2018

    Posted 06 Dec 2019 Link to this post

    I need to be able to rename a file before uploading (for example, to strip bad characters).  Simply renaming the file in any of the events doesn't work -- once it hits the actual upload mechanism, the filename goes back to the original name.

    Thanks for any assistance!

  2. Jonathan
    Jonathan avatar
    4 posts
    Member since:
    May 2018

    Posted 09 Dec 2019 in reply to Jonathan Link to this post

    I thought I should mention -- I'm using the Kendo React Uploader.
  3. Stefan
    Admin
    Stefan avatar
    3039 posts

    Posted 10 Dec 2019 Link to this post

    Hello, Jonathan,

    I was able to change the name using the onAdd event:

    https://stackblitz.com/edit/react-hajozj?file=app/main.jsx

    Please have in mind that the Upload has to be in controlled mode, as this will allow the developer to have full control over the uploaded files:

    https://www.telerik.com/kendo-react-ui/components/upload/modes/#toc-controlled-mode

    I hope this is helpful.

    Regards,
    Stefan
    Progress Telerik

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  4. Nilton
    Nilton avatar
    8 posts
    Member since:
    Oct 2017

    Posted 02 Jun 2020 in reply to Stefan Link to this post

    I am with the same issue here.

     

    Using the change proposed by @Stefan on the `onAdd` event can fix for what we see.

     

    But this approach doesn't rename the files sent to the backend after clicking on the Upload button.

    Do you know how to handle this?

     

    Please take a look on the below message...

    It is log response from the API request on backend.

     

    ```

    Processing by Api::V1::RequestsController#upload_photo as JSON
    Parameters: 
    {
      "uuid"=>"b074af81-3ef9-477c-8642-b75807d8e7ca", 
      "picture"=>#<ActionDispatch::Http::UploadedFile:0x00007fa1bd879270 @tempfile=#<Tempfile:/var/folders/1w/xmvzf1vx20x73xc3c5nb2wv40000gn/T/RackMultipart20200602-99071-bngk60.png>, @original_filename="image.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"picture\"; filename=\"image.png\"\r\nContent-Type: image/png\r\n">,
      "id"=>"123165"
    }

    ```

  5. Stefan
    Admin
    Stefan avatar
    3039 posts

    Posted 03 Jun 2020 Link to this post

    Hello, Nilton,

    Indeed with the current version and name that will be set will be only visible in the upload list.

    If we need to change it in the  data that will be sent to the server, the change has to be made on the onBeforeUpload event:

    onBeforeUpload = event => {
          event.files[0].name = 'customName.jpg';
      }
    As this requires modifications to the source code as well to apply it to the actual file, we made a pull request with the change.

    The new functionality is expected to be in the dev version tomorrow.

    Regards,
    Stefan
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
  6. Talin
    Talin avatar
    2 posts
    Member since:
    Feb 2019

    Posted 08 Feb in reply to Stefan Link to this post

    Did this new functionality (modifying the original filename as it is passed to the server) end up making it into the released code? I'm still having trouble getting a transformed file name from our client to our api by way of any of the existing Uploader events.
  7. Stefan
    Admin
    Stefan avatar
    3039 posts

    Posted 09 Feb Link to this post

    Hello, Talin,

    This has been added in version 3.15.0:

    https://www.telerik.com/kendo-react-ui/components/changelogs/ui-for-react/#768ebfec-180e-57de-8d85-9589ff4cf16b

    `upload: file name from state is not applied to form data during upload`

    If the issue still occurs, please share an example reproducing the issue and I will be happy to inspect it locally,

    Regards,
    Stefan
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

  8. Talin
    Talin avatar
    2 posts
    Member since:
    Feb 2019

    Posted 09 Feb in reply to Stefan Link to this post

    Upgraded from 3.11.0 to 3.18.0. Works perfectly! Problem resolved. Thank you!
Back to Top