-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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);
}
}
}
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.
Hello luiggi,
Could you please test the following fiddle?
http://zkfiddle.org/sample/2kopnr6/5-Multi-file-upload#source-1
Best Regards,
Darksu
Asked: 2016-08-25 13:02:04 +0800
Seen: 25 times
Last updated: Aug 28 '16
ZK Clustering, Session Replication Question [closed]
ZK Tomcat 7 Cluster/Session Replication
how to deploy zk application with tomcat startup
Call to zkcomet failing the first time
ZK 6.5.2 and memory leak stopping Tomcat 7.0.32
ZK on tomcat7 not working when accessing by IP
how do I map my domain name to an ZK application in TOMCAT server ...