Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

A project

I've been called a god before.
Joined
Aug 5, 2014
Messages
3,212
I have a server where i will put my images to. Now i am wondering what would be the best wa to transfer images from client (java) to my server (php). I read i can use two options:

a) Sockets
b) byte(code?)

Which one would be better and why? If there is anything else that is even better, i would like You to tell me what is it. Thank you
 
First Bot Author
Joined
Aug 7, 2013
Messages
262
Sockets are intended to remain opened, so unless you have a chat, they're probably not a good idea.
You can make simple POST requests with the image data and PHP will be able to handle it.
 
Joined
Nov 3, 2013
Messages
609
Just use the ImageIO class. It will do an http request under the hood.

Ex:
Code:
URL url = new URL("http://www.website.com/image/mypic.jpg");
Image image = ImageIO.read(url);

Take a look at lines 143-180 here for an example on how to save the files out to a local image cache:
Exia-Mining-All-In-One/AIOMinerGUI.java at master · JohnRThomas/Exia-Mining-All-In-One · GitHub

Edit: Sorry read that wrong, you want to go java -> server. My bad.

Check out this link:
Send image file using java HTTP POST connections
 
I've been called a god before.
Joined
Aug 5, 2014
Messages
3,212
Sockets are intended to remain opened, so unless you have a chat, they're probably not a good idea.
You can make simple POST requests with the image data and PHP will be able to handle it.
How exactly? I am trying to find something on google. but everyhting is outdated.
Just use the ImageIO class. It will do an http request under the hood.

Ex:
Code:
URL url = new URL("http://www.website.com/image/mypic.jpg");
Image image = ImageIO.read(url);

Take a look at lines 143-180 here for an example on how to save the files out to a local image cache:
Exia-Mining-All-In-One/AIOMinerGUI.java at master · JohnRThomas/Exia-Mining-All-In-One · GitHub

Edit: Sorry read that wrong, you want to go java -> server. My bad.

Check out this link:
Send image file using java HTTP POST connections
 
Top