upload attribute accept multiple file extensions

asked 2014-09-12 17:40:52 +0800

meh gravatar image meh
57 1


I want to use the upload attribute to restrict the allowable files to upload by their extensions (.pdf and .docx only). The following does not work for me:

<button label="Browse" upload="true,maxsize=-1,accept=.png,.pdf" />

The accept attribute does not seem to work at all on Firefox 31.0

Using Chrome 37.0, it works if only one file extension is specified, but not for multiple extensions.

I am using zk 7.0.2

Can anyone help?

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted

answered 2014-09-13 11:24:31 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8

updated 2014-09-13 11:25:08 +0800

Try below code

  <button label="Upload Image" upload="true,maxsize=300">        
                        <attribute name="onUpload">
                                org.zkoss.util.media.Media media = event.getMedia();            
                                if (media instanceof org.zkoss.image.Image) {               
                                    org.zkoss.zul.Image image = new org.zkoss.zul.Image();               
                                } else {               
                                    Messagebox.show("Not an image: "+media, "Error", Messagebox.OK, Messagebox.ERROR);               
                    <separator />    
                    <vlayout id="pics" height="360px" style="overflow:auto" />
link publish delete flag offensive edit


Thanks for the answer, but that's not really what I want to do. The accept attribute will only allow the user to select certain files (all others will be greyed out in the file browser). Your solution checks the file type only after it has already been uploaded.

meh ( 2014-09-13 16:22:50 +0800 )edit

Then you can check this http://tracker.zkoss.org/browse/ZK-2215 look like its a bug not resolve yet by the way which zk version you are using?

sjoshi ( 2014-09-14 18:07:35 +0800 )edit

I am using zk 7.0.2 on mac os x 10.7.5. Firefox allows selection of all files and Chrome allows only the first filetype on the list.

meh ( 2014-09-15 08:11:09 +0800 )edit

answered 2019-12-11 20:58:09 +0800

Niravdas gravatar image Niravdas

try this

<button upload="true,accept=.json | .geojson" label="Import"/>

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2014-09-12 17:40:52 +0800

Seen: 67 times

Last updated: Dec 11 '19

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More