• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Upload File on a web Server From client application

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
------------------
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And i'm trying to post a document to the web server!
 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's done.
Thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic