• Post Reply Bookmark Topic Watch Topic
  • New Topic

Upload File on a web Server From client application  RSS feed

 
Jacquis Dzogang
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i have found the way to post a form-data to my web server ( + Coldfusion).
But i don't know how to send a file (*.doc or *.zip) with that form-data? like an upload from a web browser.
this is my source code.
-----------------
sb.append( URLEncoder.encode("Name") + "=" );
sb.append( URLEncoder.encode("Jacquis") );
sb.append( "&" + URLEncoder.encode("UploadFile") + "=" );
for (int i=0; i < fileBuff.length; i++)
{
sb.append(fileBuff[i]);
}
String formData = sb.toString();
URL url = new URL("http://myIISServer/index.cfm");
HttpURLConnection urlcon = (HttpURLConnection)url.openConnection();
urlcon.setRequestMethod("POST");
urlcon.setRequestProperty("ENCTYPE","multipart/form-data");
urlcon.setRequestProperty("Content-type","application/x-www-form-urlencoded");
urlcon.setDoOutput(true);
urlcon.setDoInput(true);
PrintWriter pout = new PrintWriter( new OutputStreamWriter(
urlcon.getOutputStream( ), "8859_1"), true );
pout.print( formData );
pout.flush( );
----------------------
i received all but the upload file is not identified by my server side application.
------------------
 
Jared Krull
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to upload files from a html form, have a look at this set of classes.
http://www.servlets.com/cos/index.html
Download the zip and look at the docs included....
I think the MultiPartRequest is what you are after.
 
Jacquis Dzogang
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answer.
But that solution can't help me because i'm not writing a servlet based application.
I'm writting a simple java application that works like a web browser.
 
Jacquis Dzogang
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And i'm trying to post a document to the web server!
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"jdzogang"

The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
------------------

Mahindrakar
IBM Application Server & Developer Forum Moderator

Consultant - Zensar Technologies ,Pune India.
SCJP2, SCJD2 & SCJEA (Part I)
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's done.
Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!