*
The moose likes Beginning Java and the fly likes uploading files with java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "uploading files with java" Watch "uploading files with java" New topic
Author

uploading files with java

Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
I'm just wondering, is there some way in java to upload a file to the internet?
I have one of those free web pages (you know, with the advertisements). Anyway, the way I usually upload a file, is I go to the internet site of my page and click a button and choose a file and then click another button to upload it. But even though I want to upload a lot of files, I can upload only one file at a time. So I have to spend hours just clicking file icons. So I wonder, is there any way to write a java program that will do this for me?
One way this can be done is to to write a java program that will start up the internet browser and click buttons and click items in a list. I don't know if java programs can do that or not.
A more direct way, I suppose, is to write a program that will upload files directly, without even needing a browser. But I guess I would need some special password or access or something.
Maybe there is some other way to do it. I don't know. I've written a lot of java, but I'm clueless about how java works on the internet.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

Check out Apache's HttpClient library.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Kerry Baer
Ranch Hand

Joined: Jun 23, 2010
Posts: 39
Apache Commons - FileUpload Control

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8



But that's code to run on the server, when somebody uploads a file to it. Sounds like Kevin's requirement is on the client side.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Rob Prime wrote:Check out Apache's HttpClient library.


Yep, this is the code to use. But don't think of it as "pressing buttons". That's what you have to do to make a browser upload a file, but what the browser is actually doing is sending HTTP requests and receiving HTTP responses. Your task is to identify the requests being sent and to replicate them in your Java code. The HttpClient library helps you to do that without also having to learn the tedious details of the HTTP protocol.
Kerry Baer
Ranch Hand

Joined: Jun 23, 2010
Posts: 39
You could write a java applet that would run on the client end. You may have to resort to FTP by doing so (someone please confirm - I don't have much experience writing applets)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

That's not going to help Kevin, as a) it's an existing web application, and b) he's not hosting it, he's using it.
 
wood burning stoves
 
subject: uploading files with java