0

File Path

asked 2009-06-11 12:07:10 +0800

nasrinivasanmca gravatar image nasrinivasanmca
30 1

Dear Sir/Madam,
I'm new for zk. I'm using upload event in my project. But i don kno how to store the selected file in the particular folder.
And also i cant get the path of the selected file.
Pls help me how to store the selected file into folder using upload event.

pls mail me solution my mail id. Mail ID is [email protected]

delete flag offensive retag edit

12 Replies

Sort by ยป oldest newest

answered 2009-06-11 14:54:07 +0800

sousa1981 gravatar image sousa1981
573 4

updated 2009-06-11 14:54:31 +0800

The following code, will save the uploaded file in root folder c:/, check this line "new FileOutputStream("c:/" + media.getName());"

Hope this help you.

ZUL FILE:

<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?>
<?evaluator name="mvel"?>

<zk>	
	<window id="uploadForm" title="UPLOAD TESTE" width="100%" height="100%" border="normal" use="com.xxx.UploadForm">		
		<button label="Upload" onClick="uploadForm.upload()"/>
		<vbox id="pics" />
	</window>	
</zk>

JAVA FILE:

package com.xxx;

import java.io.FileOutputStream;
import java.io.OutputStream;

import org.zkoss.util.media.Media;
import org.zkoss.zul.Fileupload;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Window;


/**
 * @author marcos.sousa
 *
 */
public class UploadForm extends Window {
	
	public UploadForm() {
		
	}
	
	public void upload() {
		try {
			Media[] media = Fileupload.get(-1);
			if (media != null) {
				for (int i = 0; i < media.length; i++) {
					byte[] uploadedfile = org.apache.commons.io.IOUtils.toByteArray(media<i >.getStreamData());					
					OutputStream out = new FileOutputStream("c:/" + media<i >.getName());
					out.write(uploadedfile);
					out.close();
				}
			}
		} catch (Exception e) {
			showError("ERROR " + e.getMessage());
		}
	}
	
	/**
	 * TODO: Document Me
	 */
	public void showInfo(String mensagem) {
		try {
			Messagebox.show(mensagem, "XXX", Messagebox.OK, Messagebox.INFORMATION);
		} catch (InterruptedException interruptedException) {
		}
	}

	/**
	 * TODO: Document Me
	 */
	public void showError(String mensagem) {
		try {
			Messagebox.show(mensagem, "XXX", Messagebox.OK, Messagebox.ERROR);
		} catch (InterruptedException interruptedException) {
		}
	}

}

link publish delete flag offensive edit

answered 2009-06-12 04:55:47 +0800

nasrinivasanmca gravatar image nasrinivasanmca
30 1

Dear sousa;
Tanx for replying the solution. But i don kno how to use java file. If i execute the UploadForm.java file it showing the 14 errors. And i'm doing the zk project in Ubuntu 8.10 server OS. the error is listed below:

UploadForm.java:6: package org.zkoss.util.media does not exist
import org.zkoss.util.media.Media;
^
UploadForm.java:7: package org.zkoss.zul does not exist
import org.zkoss.zul.Fileupload;
^
UploadForm.java:8: package org.zkoss.zul does not exist
import org.zkoss.zul.Messagebox;
^
UploadForm.java:9: package org.zkoss.zul does not exist
import org.zkoss.zul.Window;
^
UploadForm.java:16: cannot find symbol
symbol: class Window
public class UploadForm extends Window {
^
UploadForm.java:24: cannot find symbol
symbol : class Media
location: class com.xxx.UploadForm
Media[] media = Fileupload.get(-1);
^
UploadForm.java:24: cannot find symbol
symbol : variable Fileupload
location: class com.xxx.UploadForm
Media[] media = Fileupload.get(-1);
^
UploadForm.java:27: package org.apache.commons.io does not exist
byte[] uploadedfile = org.apache.commons.io.IOUtils.toByteArray(media.getStreamData());
^
UploadForm.java:43: cannot find symbol
symbol : variable Messagebox
location: class com.xxx.UploadForm
Messagebox.show(mensagem, "XXX", Messagebox.OK, Messagebox.INFORMATION);
^
UploadForm.java:43: cannot find symbol
symbol : variable Messagebox
location: class com.xxx.UploadForm
Messagebox.show(mensagem, "XXX", Messagebox.OK, Messagebox.INFORMATION);
^
UploadForm.java:43: cannot find symbol
symbol : variable Messagebox
location: class com.xxx.UploadForm
Messagebox.show(mensagem, "XXX", Messagebox.OK, Messagebox.INFORMATION);
^
UploadForm.java:53: cannot find symbol
symbol : variable Messagebox
location: class com.xxx.UploadForm
Messagebox.show(mensagem, "XXX", Messagebox.OK, Messagebox.ERROR);
^
UploadForm.java:53: cannot find symbol
symbol : variable Messagebox
location: class com.xxx.UploadForm
Messagebox.show(mensagem, "XXX", Messagebox.OK, Messagebox.ERROR);
^
UploadForm.java:53: cannot find symbol
symbol : variable Messagebox
location: class com.xxx.UploadForm
Messagebox.show(mensagem, "XXX", Messagebox.OK, Messagebox.ERROR);
^
14 errors
[email protected]:/usr/local/tomcat/webapps/log$ javac UploadForm.javaUploadForm.java:6: package org.zkoss.util.media does not exist
import org.zkoss.util.media.Media;
^
UploadForm.java:7: package org.zkoss.zul does not exist
import org.zkoss.zul.Fileupload;
^
UploadForm.java:8: package org.zkoss.zul does not exist
import org.zkoss.zul.Messagebox;
^
UploadForm.java:9: package org.zkoss.zul does not exist
import org.zkoss.zul.Window;
^
UploadForm.java:16: cannot find symbol
symbol: class Window
public class UploadForm extends Window {
^
UploadForm.java:24: cannot find symbol
symbol : class Media
location: class com.xxx.UploadForm
Media[] media = Fileupload.get(-1);
^
UploadForm.java:24: cannot find symbol
symbol : variable Fileupload
location: class com.xxx.UploadForm
Media[] media = Fileupload.get(-1);
^
UploadForm.java:27: package org.apache.commons.io does not exist
byte[] uploadedfile = org.apache.commons.io.IOUtils.toByteArray(media.getStreamData());
^
UploadForm.java:43: cannot find symbol
symbol : variable Messagebox
location: class com.xxx.UploadForm
Messagebox.show(mensagem, "XXX", Messagebox.OK, Messagebox.INFORMATION);
^
UploadForm.java:43: cannot find symbol
symbol : variable Messagebox
location: class com.xxx.UploadForm
Messagebox.show(mensagem, "XXX", Messagebox.OK, Messagebox.INFORMATION);
^
UploadForm.java:43: cannot find symbol
symbol : variable Messagebox
location: class com.xxx.UploadForm
Messagebox.show(mensagem, "XXX", Messagebox.OK, Messagebox.INFORMATION);
^
UploadForm.java:53: cannot find symbol
symbol : variable Messagebox
location: class com.xxx.UploadForm
Messagebox.show(mensagem, "XXX", Messagebox.OK, Messagebox.ERROR);
^
UploadForm.java:53: cannot find symbol
symbol : variable Messagebox
location: class com.xxx.UploadForm
Messagebox.show(mensagem, "XXX", Messagebox.OK, Messagebox.ERROR);
^
UploadForm.java:53: cannot find symbol
symbol : variable Messagebox
location: class com.xxx.UploadForm
Messagebox.show(mensagem, "XXX", Messagebox.OK, Messagebox.ERROR);
^
14 errors

Pls, give me full details how to use the above given file...

link publish delete flag offensive edit

answered 2009-06-12 06:53:00 +0800

sousa1981 gravatar image sousa1981
573 4

Are you using Eclipse IDE?

Append the following to your classpath:
> All ZK Staff, those jars start with z*.jar + bsh.jar + mvel.jar + commons-*.jar all those jars are distributed by ZK, you will found it in ext folder.
> In your project properties go to Java Build Path then in tab Libraries click on Add Library button on the right side then append your Server Runtime and JRE System Library

link publish delete flag offensive edit

answered 2009-06-12 12:44:45 +0800

nasrinivasanmca gravatar image nasrinivasanmca
30 1

Dear sousa;
No sousa, i'm not using eclipse ide. I'm normally using the gedit editor in ubuntu.
I'm not using any more editor.
In the my application folder i imported all the jar files.


Regards
Srinivasan.N.A([email protected])

link publish delete flag offensive edit

answered 2009-06-12 13:18:36 +0800

sousa1981 gravatar image sousa1981
573 4

Ohhhhhhhhhhhhhhhhh

Install eclipse IDE, you will have more fun programming using it.

I have eclipse Ganymede installed in my ubuntu 9.04 with ZK Studio.

Importing those jars z*.jar + bsh.jar + mvel.jar + commons-*.jar I think is enough.

cheers

link publish delete flag offensive edit

answered 2009-06-15 10:04:08 +0800

nasrinivasanmca gravatar image nasrinivasanmca
30 1

Hi Sousa, i can'd install eclipse Ganymede with zk studio.

If any other solution is there to upload a file into local system folder. But tanx for replying previous solution, but i cant do it..

link publish delete flag offensive edit

answered 2009-06-15 16:04:08 +0800

sousa1981 gravatar image sousa1981
573 4

Hi Srinivasan,

Looks like until now you didn't get it to work isn't it?

What are your problems now?

link publish delete flag offensive edit

answered 2009-06-15 16:06:20 +0800

sousa1981 gravatar image sousa1981
573 4

You can contact me direct at marcosvasousa AT gmail DOT com

Add to google talk if possible.

link publish delete flag offensive edit

answered 2009-06-16 05:08:49 +0800

nasrinivasanmca gravatar image nasrinivasanmca
30 1

hi sousa,
I sended request thru my gmail chat list. Accept and answer it my doubts.

Actually yesterday i tried to install eclipse IDE, but its failure, in my application using jasper i reports, before eclipse installation it works well. But after installed eclipse IDE genymade the i report showing the exception PermGen space.

Regards
Srinivasan.N.A

link publish delete flag offensive edit

answered 2010-03-08 04:24:08 +0800

nageshprabhug gravatar image nageshprabhug
69 1

hi sousa, can you please tell me how to use getMedia() funtion in zscript to retrieve values...... please help me......

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2009-06-11 12:07:10 +0800

Seen: 2,308 times

Last updated: Apr 26 '11

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