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

Filetype filter (.pdf, .doc)...etc

7 Answers 2484 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 02 Dec 2012, 01:08 AM
Is there a way to only allow the user to control the selectable file types?

I know I can get the information once they select the file but I'd prefer to filter the list to only .pdf, or whatever.

7 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 04 Dec 2012, 02:57 PM
Hello Bob,

You can use an accept HTML attribute, but keep in mind it is only supported by modern browsers.


@(Html.Kendo().Upload()
    .Name("files")
    .HtmlAttributes(new { accept = "image/*" })
)


Regards,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Igor
Top achievements
Rank 2
answered on 11 Oct 2013, 12:51 AM
Hi!

here is also one idea that might be useful for somebody
i have not tested if it could filter filesize, but i suspect so.
@(Html.Kendo().Upload()
 .Name("docUpload")
 .Multiple(false)
  .ShowFileList(false)
  .Events(e => e.Upload("onUpload"))
  .Async(a => a
        .Save("DocUpload", "Documents")
         .AutoUpload(true))
)
 
<script>
  function onUpload(e) {
        var files = e.files;
 
        $.each(files, function () {
 
            if (this.extension.toLowerCase() != ".doc") {
                alert("Only .doc files can be uploaded!")
                e.preventDefault();
            }
 
            if (this.size / 1024 / 1024 > 5) {
                alert("Max 5Mb file size is allowed!")
                e.preventDefault();
            }
        });
    }
</script>


0
Francis
Top achievements
Rank 1
answered on 20 Feb 2014, 06:49 PM
I would like the user to be able select only certain file types.  For instance, ".csv" | ".xlsx" | "*.* All files".  How do I achieve this?
0
Igor
Top achievements
Rank 2
answered on 20 Feb 2014, 07:10 PM
Well, according to documentation it is not possible yet to configure the file open dialog box.
You could only "catch" the upload event in order to have file extensions be filtered:
http://docs.telerik.com/kendo-ui/api/web/upload#events-upload

or you may use and alternative way to have extensions like that with jQuery:
http://stackoverflow.com/questions/8938124/how-to-filter-input-type-file-dialog-by-specific-file-type
0
krishna
Top achievements
Rank 1
answered on 31 Mar 2015, 07:04 AM
Is there any way yet, on how to configure the file open dialogue box as Igor said ?
I need to display the file extensions allowed, in the dropdown of that dialogue box, so that user can sort the files accordingly !
Kindly respond.
0
krishna
Top achievements
Rank 1
answered on 31 Mar 2015, 07:05 AM
Is there any way yet, on how to configure the file open dialogue box as Igor said ?
I need to display the file extensions allowed, in the dropdown of that dialogue box, so that user can sort the files accordingly !
Kindly respond.
0
Dimiter Madjarov
Telerik team
answered on 31 Mar 2015, 07:32 AM

Hello Gopikrishna,

You could use the accept html attribute to specify the files that should be displayed by default in the file selection window, but it it not possible to restrict the user from selecting another one by changing the value in the file types dropdown.

Regards,
Dimiter Madjarov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Upload
Asked by
Bob
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Igor
Top achievements
Rank 2
Francis
Top achievements
Rank 1
krishna
Top achievements
Rank 1
Dimiter Madjarov
Telerik team
Share this question
or