1

I would like in my AngularJS app call .jar for uploading images/files. Angular could send blob data (image information) to that .jar, and for example folder name where image would be stored.

So my java method could have 2 params - of blob type and string type. Now, how can I pass those params to java jar? I would like to avoid servlets for image upload. I think of generate .jar of simple custom upload class in Java as solution.

But, now question raises - how to pass non string params to main method of Java class which accepts String args[]? My method must have params too. So that means, if I got it right - main method should accept params from JavaSrcipt and hand it over to method. Am I right?

How could I achieve that? Maybe example with code?

Max
  • 6,821
  • 3
  • 43
  • 59
DarioBB
  • 663
  • 2
  • 8
  • 29

1 Answers1

0

You can just cast them to whatever you like in your Java program, after retrieving them as strings. But , why are you using Java client side?

overburn
  • 1,194
  • 9
  • 27
  • I don't. I use AngularJS for client. How can I output stream of blob cast to string, and after that, pass them as strings and them again get them as output stream? – DarioBB May 03 '16 at 09:01
  • I'll loose my stream/blob data if I cast it to string. I don' see any way to cast stream to string and later get it back overburn. How can I do that? – DarioBB May 03 '16 at 09:15
  • You could try encoding the blob into a base-64 string. You could use a function such as btoa() – overburn May 03 '16 at 09:21
  • Ok, thans for info. And in my jar, do I have to have main method, or just my custom method would be enough to jar to work? Also, do I have to generate .jar to produce messages with standard output? – DarioBB May 03 '16 at 09:27
  • It seems you don't need a main method in an applet. My experience with this is limited, but I believe that yes, you need a jar to embed into the webpage. Although, why you would choose to use a java applet in this day and age is beyond me. – overburn May 03 '16 at 09:30
  • I don't want applet, no way. I just want to use Java as backed for upload. Not applet. I'm using Angular on front. No Java would be used on front. – DarioBB May 03 '16 at 09:37
  • Oh. In that case you just use ajax to send the request to the server, and on the server you process that request (in whatever way your stack handles requests). If you aren't, you should use a framework such as https://www.playframework.com/ – overburn May 03 '16 at 09:39
  • I know what ajax does and AngularJS triggers it. I don't want to use any Java framework. I want to upload file with my custom class without any framework. – DarioBB May 03 '16 at 09:48
  • Oh okay then, you just need to listen for a request from the client, and then save the received data however you like. This should help - http://stackoverflow.com/questions/13551803/what-is-the-proper-way-to-listen-to-http-requests – overburn May 03 '16 at 09:51