File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes copying images in client-server environment? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "copying images in client-server environment?" Watch "copying images in client-server environment?" New topic

copying images in client-server environment?

Ralph Ching

Joined: Jul 18, 2006
Posts: 15
how do i transfer images from the client to the server using only core java (no jsp and servlets)?

the scenario is, the user uploads an image from the form, with the user specifying the location of the image like "C:\images\img.jpg", and i have to copy it from his computer to the server using http. i was playing around with URL and URLConnection but was having issues regarding the url, cause i can't work out a way to convert the image path to http path.

i know i'm doing it wrong and would like to know the best way to implement the problem.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Which part are you trying to implement - the client or the server, or both?

When you say "no servlets, no JSP", yet you do want to use HTTP, what do you have on the server-side? Must be some kind of HTTP server. Can it accept HTTP file uploads?
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

Hmm... I think I'll move this to the intermediate forum. this seems a little advanced for here.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ralph Ching

Joined: Jul 18, 2006
Posts: 15
im implementing both client side & server side code for this problem. im using an mvc architecture where the jsp collects the data which in this case is the path to the image on the client's terminal, and the jsp & servlet transfers control to the model (a bunch of java files) and the model is supposed to perform the transfer of files.

the "methodology" for this project limits the way the jsp & servlets work in a way that those 2 does not do much server side other than passing the data to the model. im actually using JBoss for this project (so i think that is an http server).
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I'm still confused ... is the client a browser or a Java program?

For a browser client, you can put a file upload control in an HTML form:

When the user submits the form, the browser sends a multi-part MIME request to the server. This is all to HTTP standards, but it's a bit tricky to read these requests on the server. Fortunately there are libraries around to do the job for you when the form posts to a servlet.

For a Java client, you can use sockets or a library for FTP. See the Sun Networking Tutorial for a good start on sockets.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: copying images in client-server environment?
jQuery in Action, 3rd edition