-
FEATURED COMPONENTS
First time here? Check out the FAQ!
<button label="Attach">
<attribute name="onClick">
{
org.zkoss.util.media.Media[] media = Fileupload.get(-1);
if (media != null)
{
for (int i = 0; i < media.length; i++)
{
if (media instanceof org.zkoss.image.Image)
{
org.zkoss.zul.Image image = new org.zkoss.zul.Image();
image.setContent(media);
image.setParent(pics);
}
else
{
Messagebox.show("Not an image: "+media, "Error", Messagebox.OK, Messagebox.ERROR);
break; //not to show too many errors
}
}
}
}
</attribute>
</button>
above is my code to upload the file but I am not being able to upload the fil...because the media is null. I have tried both enabling and disabling the event thread but both ways doesn't work. please help me.
please help mew I am stuck badly
Hi, bhushan2169:
Could you paste the complete code? I can reproduce your problem because I can NOT find variable "pics".
Hawk
the code in IF block is not being executed in the first place...because the media is returning null....u can remove the code from if block and then try the code...I'll post the code
Here is my code....my ultimate aim is to upload file on the server and download from the other side......
<zk>
<button label="Upload Image" upload="true,maxsize=300">
<attribute name="onUpload"><![CDATA[
org.zkoss.util.media.Media media = event.getMedia();
if (media instanceof org.zkoss.image.Image) {
org.zkoss.zul.Image image = new org.zkoss.zul.Image();
image.setContent(media);
image.setParent(pics);
} else {
Messagebox.show("Not an image: "+media, "Error", Messagebox.OK, Messagebox.ERROR);
break;
}
]]></attribute>
</button>
<separator />
<vlayout id="pics" height="360px" style="overflow:auto" />
</zk>
I am trying to run the code from the demo..but ''media'' is still null...I have tried enabling and disabling the events thread from xml file.
In above example event.getMedia(); gets null everytime.
hi, bhushan2169:
I just paste your code posted yesterday and it works without error.
you can see the running result, under the following window:
<zk> <window title="upload" border="normal">
<button label="Upload Image" upload="true,maxsize=300">
<attribute name="onUpload"><![CDATA[
org.zkoss.util.media.Media media = event.getMedia();
if (media instanceof org.zkoss.image.Image) {
org.zkoss.zul.Image image = new org.zkoss.zul.Image();
image.setContent(media);
image.setParent(pics);
} else {
Messagebox.show("Not an image: " + media, "Error", Messagebox.OK,
Messagebox.ERROR);
break;
}
]]></attribute>
</button>
<separator ></separator>
<vlayout id="pics" height="360px" style="overflow:auto" ></vlayout>
</window>
</zk>
For now, I still can't image what's problem of your code, maybe you can re-check the process of your uploading.
bhushan2169, You should check your web server configuration. I ever had the same problem with Glassfish. After changing to Tomcat, it works well
Asked: 2011-08-19 05:26:23 +0800
Seen: 806 times
Last updated: Apr 24 '12