0

Media is returning null

asked 2011-08-19 05:26:23 +0800

bhushan2169 gravatar image bhushan2169
138

<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.

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2011-08-19 10:41:21 +0800

bhushan2169 gravatar image bhushan2169
138

please help mew I am stuck badly

link publish delete flag offensive edit

answered 2011-08-23 04:41:36 +0800

hawk gravatar image hawk
3250 1 5
http://hawkphoenix.blogsp... ZK Team

Hi, bhushan2169:
Could you paste the complete code? I can reproduce your problem because I can NOT find variable "pics".

Hawk

link publish delete flag offensive edit

answered 2011-08-23 06:46:29 +0800

bhushan2169 gravatar image bhushan2169
138

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

link publish delete flag offensive edit

answered 2011-08-24 07:49:05 +0800

bhushan2169 gravatar image bhushan2169
138

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.

link publish delete flag offensive edit

answered 2011-08-24 07:49:49 +0800

bhushan2169 gravatar image bhushan2169
138

In above example event.getMedia(); gets null everytime.

link publish delete flag offensive edit

answered 2011-08-24 20:21:55 +0800

hawk gravatar image hawk
3250 1 5
http://hawkphoenix.blogsp... ZK Team

hi, bhushan2169:

I just paste your code posted yesterday and it works without error.

you can see the running result, under the following window:

ZKFiddle-Link

index.zul
<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.

link publish delete flag offensive edit

answered 2012-04-24 05:11:40 +0800

thickkoezz gravatar image thickkoezz
9

bhushan2169, You should check your web server configuration. I ever had the same problem with Glassfish. After changing to Tomcat, it works well

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: 2011-08-19 05:26:23 +0800

Seen: 806 times

Last updated: Apr 24 '12

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