0

upload image path

asked 2016-08-25 13:02:04 +0800

luiggi gravatar image luiggi
1

I'm Zk Using java to upload an image of a Tomcat Server on Debian, but uploading the picture shows error publish ( not locate the image ), but locally it works. Please help me my class

public class image extends SelectorComposer {}


@Listen("onUpload = button#upload")
    public void onUpload(UploadEvent event) {
        long millisStart = Calendar.getInstance().getTimeInMillis();
        Object contextPath = Executions.getCurrent().getDesktop().getWebApp().getRealPath("/WEB-INF/uploads/");
        String filename = contextPath.toString()+"/"+millisStart+".jpg"; //      String filename = "/home/luiggi/Documentos/testRutaImagenEnrol/"+millisStart+".jpg";
        BufferedInputStream in = null;
        BufferedOutputStream out = null;
        try {      
            if(listPath.size()<6){
                Media med = event.getMedia();                     

                InputStream fin = med.getStreamData();          
                in = new BufferedInputStream(fin);
                File baseDir = new File(contextPath.toString()); //       File baseDir = new File("/home/luiggi/Documentos/testRutaImagenEnrol/");
                if (!baseDir.exists()) {
                    baseDir.mkdirs();
                }
                File file = new File(filename);             
                OutputStream fout = new FileOutputStream(file);
                out = new BufferedOutputStream(fout);
                byte buffer[] = new byte[1024];
                int ch = in.read(buffer);
                while (ch != -1) {
                    out.write(buffer, 0, ch);
                    ch = in.read(buffer);
                }
                listPath.add(filename);         
                Clients.showNotification("Imgenes subidas: "+listPath.size()+"/6");     

            }else{              
                Clients.showNotification("Maximo de imagenes "+listPath.size()+"/6");
            }          
        } catch (Exception e) {
            logger.error("[ERROR:]!", e);
            e.printStackTrace();
            Messagebox.show("Upload failed");
            Executions.sendRedirect("menuprincipal.zul");
        }finally {
            try {
            if (out != null) 
                out.close();    

            if (in != null)
                in.close();

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
       }        
    }
delete flag offensive retag edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2016-08-26 06:54:42 +0800

IngoB gravatar image IngoB flag of Germany
256 6

updated 2016-08-26 06:55:16 +0800

Is the tomcat running with the same user ("luiggi")? or is it running with "tomcat" user? If so, you don't have write permission in the home dir of a different user.

link publish delete flag offensive edit
0

answered 2016-08-26 13:53:05 +0800

sanjoy11 gravatar image sanjoy11
1

Please search on google, i think you may find your answer.

link publish delete flag offensive edit
0

answered 2016-08-28 17:51:05 +0800

Darksu gravatar image Darksu
1991 1 4

Hello luiggi,

Could you please test the following fiddle?

http://zkfiddle.org/sample/2kopnr6/5-Multi-file-upload#source-1

Best Regards,

Darksu

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

Follow
1 follower

RSS

Stats

Asked: 2016-08-25 13:02:04 +0800

Seen: 25 times

Last updated: Aug 28 '16

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