We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Applet doesn't work like the normal program
Page Index Toggle Pages: 1
Applet doesn't work like the normal program (Read 1513 times)
Applet doesn't work like the normal program
Jul 23rd, 2009, 1:58pm
 
Hi all ! :)

So my problem is that I made a program in processing which do some stuff and finally upload on a server an image and a text file through a PHP script.
It works perfectly when I run it with Processing but when I export it, the applet upload the image file but not the text file and then do weird thing :x

I really don't understand why the program and the applet doesn't work the same  :o

Here is my code which sends the file to the script if that can help but again it works fine when I run in Processing:

byte[] sendableFile = new byte[file_output.length()];
file_output.getBytes(0, file_output.length(), sendableFile, 0);
isUploadOk = uploadHandler.UploadBinaryData(dateNowString + ".txt", sendableFile);

Thank you :)
Re: Applet doesn't work like the normal program
Reply #1 - Jul 24th, 2009, 2:15am
 
We are lacking a bit of information, like what do you use to upload the data (the UploadBinaryData name sounds familiar but the one I know has a dataMimeType additional parameter...). Not sure if that's relevant to your problem, of course.

The "do weird thing" part is a bit nebulous too... Did you have a look at the Java console? Have you an answer code?

That said, if you can upload the image and not the text, only in applet mode, I don't see why. That's why more info is welcome.
Re: Applet doesn't work like the normal program
Reply #2 - Jul 24th, 2009, 8:58am
 
Actually I think it's the same UploadBinaryData that you know (edit: it's your code actually :P), I made some modification to the class but I then get back to the "raw" version ^^

I managed to find where the applet is messing up thanks to some javascript. Here is my full code for the upload :

Code:
  DataUpload uploadHandler = new DataUpload();

 if (!uploadImage(uploadHandler, dateNowString))
   return;
 if (!uploadText(uploadHandler, dateNowString))
   return;
 is_saved = true;
}

boolean uploadImage(DataUpload uploadHandler, String dateNowString)
{
 boolean isUploadOk = false;
 isUploadOk = uploadHandler.UploadImage(dateNowString + ".png", (BufferedImage) g.image);

 return (isUploadOk);
}

boolean uploadText(DataUpload uploadHandler, String dateNowString)
{
 boolean isUploadOk = false;
 
 byte[] sendableFile = new byte[file_output.length()];
 file_output.getBytes(0, file_output.length(), sendableFile, 0);
 isUploadOk = uploadHandler.UploadBinaryData(dateNowString  + ".txt", "", sendableFile);

  return (isUploadOk);
}


So the applet messes at the UploadImage and UploadBinaryData functions. The isUploadOk boolean are at false at the end of each.
Whereas it works fine when running in Processing :x

I didn't figure out where in the DataUpload class it doesn't work but i think it's here :

Code:
      boolean isOK = StartPOSTRequest(fileName, imageMimeType);
if (!isOK)
return false;


And I really don't know why  :/
Thx for your help ;)
Re: Applet doesn't work like the normal program
Reply #3 - Jul 24th, 2009, 11:00am
 
Sabrina wrote on Jul 24th, 2009, 8:58am:
I managed to find where the applet is messing up thanks to some javascript.
I am curious, how do you do this Why don't you use the Java console The println() (and exception dumps) would go there, for example.

Quote:
So the applet messes at the UploadImage and UploadBinaryData functions.
I thought it was fine for the image

Is the PHP script on the same server as the applet file If not, the applet must be signed.
Re: Applet doesn't work like the normal program
Reply #4 - Jul 24th, 2009, 11:37am
 
PhiLho  wrote on Jul 24th, 2009, 11:00am:
I am curious, how do you do this Why don't you use the Java console The println() (and exception dumps) would go there, for example.


But how can I use the console with the applet When I export my program it creates the applet and then I can't access the console anymore. Do I do something wrong :x
For the Javascript stuff (which i did because I didn't have debug info) I just have a function in the .pde which calls a javascript function of the html page thanks to a JSObject. I can show you the code if you wanna see that ;P

PhiLho  wrote on Jul 24th, 2009, 11:00am:
I thought it was fine for the image


Actually I don't know why I said that because it doesn't work either for the image :/

PhiLho  wrote on Jul 24th, 2009, 11:00am:
Is the PHP script on the same server as the applet file If not, the applet must be signed.


Yes it is :(
Re: Applet doesn't work like the normal program
Reply #5 - Jul 24th, 2009, 12:01pm
 
When I run a Java applet (or program, though Java Web Start / JNLP), I have a Java icon appearing in the tray area (in Windows at least).
If I right-click on the icon, I have a menu and I can choose to make the Java console to appear: it logs the output and allows some commands like clearing the cache (each time you update the jar).
Re: Applet doesn't work like the normal program
Reply #6 - Jul 24th, 2009, 12:54pm
 
PhiLho  wrote on Jul 24th, 2009, 12:01pm:
When I run a Java applet (or program, though Java Web Start / JNLP), I have a Java icon appearing in the tray area (in Windows at least).
If I right-click on the icon, I have a menu and I can choose to make the Java console to appear: it logs the output and allows some commands like clearing the cache (each time you update the jar).


omg how come i didn't know that !! I love you !!  ;p

Thanks to that I saw that the link() didn't work. When only this line commented everything seems to go fine !

It's great thank you very much PhiLho ! :D
Page Index Toggle Pages: 1