• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to upload a Image using JAVA program

 
Ramesh Shanmugam
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a image in my local system. i need to upload it to a remote system.
can any one give me code snippet to upload images to remote system.

Thanks in advance
Ramesh
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your requirements are a little vague aren't they? Want to use Http, Ftp, something else? Want to use an applet, Browser? Servlet/JSP container? All important factors that need to be filled in before we can give you an answer.

If you want to upload using a Java application (Applet, Webstart, plain app) to a Servlet/JSP engine you can use HttpClient (client side) and FileUpload (server side) in the Apache Jakarta commons project.

For FTP you can also use a Jakarta (Commons Net) package. Or some other FTP library. Of course you will have to have an FTP server somewhere.

If you have a Browser as a client you can use an HTML Form with a file input and the Jakarta FileUpload package on the server side.

Hope this helps you out.
 
Ramesh Shanmugam
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using Browser as a client and i am using HTML Form with a file input.
i donno what i have to use Apache FileUpload software ... can u pls give me out some more tipe..

more over i dont want to use <Input type= "FILE" /> in my form,... i want to pass the File path alone.. using that any software has to upload the file from my local to the remote system..
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use the html file-input the upload is done automatically for you. Your browser will create a multipart http request and send the file data to the server. This is the only way of getting the data to the server if you only use a simple http client and a Webserver.

It's not possible for the webserver to access your local filesystem if you only pass a file url (eg. c:\file.txt). The webserver can never get to that file.

Ok, now we have come to that understanding. The only way to go is using <input type="file">. What do we need on the server side? You can not just upload a file to any webserver of course. The server has to know what to do with that content. You will have to parse the multipart request and process all files that have been uploaded in the request. For this you can use FileUpload in the Jakarta commons project.

Using FileUpload

You do have to have a Java Servlet/JSP container in order to use this of course. (eg. Tomcat)

I hope this is clear for you?

Ah yes, if you do not want to manually select the file (you said you do not want to use the <input type="file"> you may try to set the value (using javascript, or on the generated html) and make it invisible using CSS. Just an idea that comes to mind.
[ July 05, 2005: Message edited by: Manuel Moons ]
 
Ramesh Shanmugam
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks moons...
Probably can u pls tell me how to set the file name using Javascript and CSS..

the thing is i need to Upload image files.. will it work with Apache File Upload.. do u have any sample Code Snippet to use with FileUpload

Thanks in advance
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The apache project contains all the sample code you need.

Can't help you with the javascript and CSS stuff. Can't be to hard, can it! Search and you will find!
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the servlet forum.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ramesh Shanmugam:
Thanks moons...
Probably can u pls tell me how to set the file name using Javascript and CSS..



You can't. The user needs to choose the file.
It would be a huge security hole if websites could do this.
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right. It does not work. The value of an <input type="text"> can not be set that way. Hmm, I'm fresh out of ideas then...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic