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

Name validation when upload files

3 Answers 391 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
xin
Top achievements
Rank 1
xin asked on 12 Mar 2019, 01:46 PM

Anyone know how to do a name validation when I upload the files. Not the extension. 

<Upload
batch={false}
multiple={true}
defaultFiles={[]}
withCredentials={false}
restrictions={{
allowedExtensions: ['.xlsx', '.xls']
}}
saveUrl={'https://demos.telerik.com/kendo-ui/service-v4/upload/save'}
removeUrl={'https://demos.telerik.com/kendo-ui/service-v4/upload/remove'}
/>

Thank you Very much

 

 

 

3 Answers, 1 is accepted

Sort by
0
xin
Top achievements
Rank 1
answered on 12 Mar 2019, 06:40 PM

// get the files name

<Upload onAdd={(e) => this.handleAddFile(e)} />

handleAddFile = (e) => {

console.log("file name",e.affectedFiles[0].name)
} I can use this to get the files name, and I want to do a name validation, such as the file`s name must be  like AL-13-Annual.pdf. How to pervent upload if the name is not match?

 

0
Stefan
Telerik team
answered on 13 Mar 2019, 09:07 AM
Hello, Xin,

This can be achieved using the following approach:

1) Set the component in controlled mode by using the files property. This will allow controlling which files will be added for upload:|

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

2) Set the autoUpload to false to prevent the automatic upload:

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

3) Utilize the onAdd event where based on the file name will either add the file to the files collection or not:

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

This is an example demonstrating this:

https://stackblitz.com/edit/react-3x6dal?file=app/main.js

If this is not possible in the real example please share more details. Also, if you have a suggestion on how this can be optimized please let us know we value the feedback very high.

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
0
xin
Top achievements
Rank 1
answered on 13 Mar 2019, 08:24 PM
Thanks Stefan
Tags
General Discussions
Asked by
xin
Top achievements
Rank 1
Answers by
xin
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or