0

upload attribute accept multiple file extensions

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

meh gravatar image meh
57 1

Hi,

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

1 Answer

Sort by ยป oldest newest most voted
0

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

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

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

Try below code

<zk>
  <button label="Upload Image" upload="true,maxsize=300">        
                        <attribute name="onUpload">
                            <![CDATA[            
                                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();               
                                    image.setContent(media);                
                                    image.setParent(pics);           
                                } else {               
                                    Messagebox.show("Not an image: "+media, "Error", Messagebox.OK, Messagebox.ERROR);               
                                    break;            
                                }       
                             ]]>
                            </attribute>    
                    </button>    
                    <separator />    
                    <vlayout id="pics" height="360px" style="overflow:auto" />
</zk>
link publish delete flag offensive edit

Comments

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
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

Follow
2 followers

RSS

Stats

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

Seen: 62 times

Last updated: Sep 13 '14

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