Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Joe Ess

NEED HELP! I want to post a file thru HTTP to be processed on my Server Side APIs.  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I desperate need help.

I am trying to load a file from my client application to send to my server side API though a URL connection.

The problem is that on the server side i am not able to catch the inputstream in the response. Can anyone please help, am I doing this correctly?

here is my code


url = new URL(apiurl + "?method=transfer.uploadfile&userauth=" + userauth+ "&apikey=" + apikey+ "&transfer=" +transferid+
"&filename=" + file.getName() + "&apisig=" + signature);

urlConn = url.openConnection();

OutputStream out = urlConn.getOutputStream();
FileInputStream in = new FileInputStream(file);

int len;
byte[] buffer = new byte[1024];
while((len = != -1) {
out.write(buffer, 0, len);


Server side=>

ServletInputStream in = req.getInputStream();
//Iterator it = this.upload.parseRequest(req).iterator();
//FileItem item;
String uploadFileName;
String uploadFilePath;
FileOutputStream outputStream;
//ServletOutputStream out = res.getOutputStream();
// initialize a file to hold the uploaded data
uploadFileName = System.currentTimeMillis()+"-"+Math.round(Math.random()*1000000);
uploadFilePath = this.tempDir+ File.separator +"complete" + File.separator +uploadFileName;
File uploadFile = new File(uploadFilePath);
outputStream = new FileOutputStream(uploadFile);

// save to temp file
int len;
byte[] buffer = new byte[1024];
while((len = != -1)
System.out.println("<<<<<<" + len);

Posts: 9509
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uploading a file via HTTP is a little more involved than the code you've written. Have a look at our FAQ entry FileUpload for some utilities that can help you along.
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!