0

Saving Uploaded Files

asked 2008-08-11 11:03:44 +0800

DEEP gravatar image DEEP
34

Hello,
Can any one give a code for saving the upload file to
1. to File System
2. to Database

Both Samples are required.

File Types i am uploading are Images, Multipage Tiff, PDF, Word File etc..

Thanks

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2008-08-11 18:13:38 +0800

hkn gravatar image hkn
246 3

Hello, there is somewhere an example as far as I remember in the HowTos.

Here is an reduced example I extracted from an app:

public void onClickLogoUpload(Event event) throws Exception {
Object media = Fileupload.get();
if (media instanceof org.zkoss.image.Image) {
// Write uploaded image as a file
FileOutputStream osw = new FileOutputStream("<ImageFilePathAndName>"); // to test enter a valid file path
osw.write( ((org.zkoss.image.Image)media).getByteData() );

// or continue working with the image data, here display the image
Image image = new Image();
image.setContent((org.zkoss.image.Image) media);
image.setId("<id_image??????>"); // add your ID
id_display_image.getChildren().clear(); // can be <z:hbox id="id_display_image" />
image.setParent(id_display_image); // display the image
// and here is the access to the binary data
org.zkoss.image.Image img = image.getContent();
img.getByteData() ; // returns the binary of the image you can save to a BLOB type column

} else if (media != null)
Messagebox.show("Not an image:" + media, "Error", Messagebox.OK, Messagebox.ERROR);
}


I hope that gives some hints .....
sorry if not

link publish delete flag offensive edit

answered 2008-08-11 22:12:22 +0800

Vic gravatar image Vic
54

updated 2008-08-11 22:12:57 +0800

Hi. You have to use next way:

Media media;
try {
	media = Fileupload.get(true); //<--true
} catch (InterruptedException e) {
	return "Error in file loading";
}
InputStream is=media.getStreamData();

After this you are welcome to save data from InputStream to the file or get byte array and send it to the DB.

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: 2008-08-11 11:03:44 +0800

Seen: 423 times

Last updated: Aug 11 '08

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