Use KendoReact to simulate <input type="file">

1 Answer 60 Views
Upload
Charlie
Top achievements
Rank 1
Iron
Charlie asked on 22 Jan 2022, 12:54 PM

I have a standard HTML input with the following configuration.

<input type='file' placeholder='Select file' onChange={handleChange} />

The input is processed by a button click with event handlers attached.

I want to replace this element with a KendoReact component that can restrict file types uploaded. Is the Upload component with autoUpload disabled the best option? 

     <Upload
     autoUpload={false}
     onChange={handleChange}
     onClick={uploadFile}
     batch={false}
     restrictions={{ allowedExtensions: ['.jpg', '.png'] }}
     defaultFiles={[]}
     withCredentials={false} />

How do I expose the onClick event for the Upload component's submit button?

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 24 Jan 2022, 05:53 AM

Hello,

Yes, the KendoReact Upload with autoUpload set to false is the best option to replicate this.

Also, you can use the controlled version of the component to have the files in the state. That will allow accessing the files from the state when the button is clicked:

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

Each file has a getRawFile method that returns the real file instance:

https://www.telerik.com/kendo-react-ui/components/upload/api/UploadFileInfo/#toc-getrawfile

Regards,
Stefan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Upload
Asked by
Charlie
Top achievements
Rank 1
Iron
Answers by
Stefan
Telerik team
Share this question
or