Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

uploading files with java

 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out Apache's HttpClient library.
 
Kerry Baer
Ranch Hand
Posts: 39
 
Paul Clapham
Sheriff
Posts: 21319
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Sheriff
Posts: 21319
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic