File upload using zk 5.0.5

I am trying to upload jar file using zk(5.0.5). While uploading i have checked its format (extension) for that I have used getFormat() API of the Media (org.zkoss.util.media.Media).

code:

browsebtn.addEventListener("onUpload",new EventListener() {             
public void onEvent(Event event) throws Exception {
                private Media uploadedMedia;
                uploadEvent=(UploadEvent) event;
                uploadedMedia=uploadEvent.getMedia();
                if(uploadedMedia!=null){
                    String fileName=uploadedMedia.getName();
                    fileFormat=uploadedMedia.getFormat(); 
                    System.out.println("File Format Name"+fileFormat);
                } 
            }           
});

Problem is that for internet explorer i get format as zip , for chrome and Firefox i get its format as octet-stream . Why there is such mismatching for different browsers . How to solve this problem ?(I dont want to any hard coding such as browser check)

Answers


You can try with;

LobData data = ZkUtils.media2LobData(uploadedMedia);

Then use that data:

data.getFormat();

I think the best way is to check the mime type to get the type, format, extension... of your file and to prevent some security attacks, for example you can use this :

File f = new File("test.pdf");
    System.out.println("Mime Type  of " + f.getName() + " is " +
                         new MimetypesFileTypeMap().getContentType(f));
    // "Mime Type of test.pdf is application/pdf"

You can find here the list of the most popular mime types.

Hope this helps.


Need Your Help

Apache .htaccess to hide both .php and .html extentions

apache .htaccess mod-rewrite url-rewriting rewrite

What lines should I add to remove both .html and .php extensions from my site?