-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
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
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.
Asked: 2008-08-11 11:03:44 +0800
Seen: 423 times
Last updated: Aug 11 '08