Upload files through HTTP call

Guys -My tech lead is asking me to upload multiple files to a server by way of making HTTP Calls. The Input parameters would then be byte stream. 1. Does this make sense ?2. Any leads on how I could accomplish this?Thank you.
[260 byte] By [BabuLala] at [2007-11-26 17:48:42]
# 1
Read the first part of this article. HttpClient is what you're looking for. http://www.theserverside.com/tt/articles/article.tss?l=HttpClient_FileUploadYou can also do it with core Java using URL / URLConnection / HttpURLConnection
Jasprea at 2007-7-9 5:01:05 > top of Java-index,Java Essentials,Java Programming...
# 2
I'd definitely second the recommendation for the use of the Apache Commons File Upload utilities for this. They make it an absolute breeze.
dcmintera at 2007-7-9 5:01:05 > top of Java-index,Java Essentials,Java Programming...
# 3

Guys - Thanks for your help. You both rock.

I passed the URI name as http://10.53.14.148:7002/myName/ and filename as "c:\\crazyname.txt" and get a response code of statusLine>>>HTTP/1.1 200 OK

BUT - cannot find the file on my Application Server. No Exception is being reported too.

Wondering what is happening.

BabuLala at 2007-7-9 5:01:05 > top of Java-index,Java Essentials,Java Programming...
# 4
You have to pull the FileItem out of the request. I'm not entirely sure when the file is materialized, but it may well be at this point. Depending on how you have things set up you may be materializing it in memory and not on disk. As always, check the docs.
dcmintera at 2007-7-9 5:01:05 > top of Java-index,Java Essentials,Java Programming...
# 5

Not sure I understand. This is what I am doing -

mPost = new MultipartPostMethod("http://10.53.14.148:7002/"); File f1 = new File(c:\\crazyname.txt);

mPost.addParameter(f1.getName(), f1);

int statusCode1 = client.executeMethod(mPost);

System.out.println("statusLine>>>" + mPost.getStatusLine());

> You have to pull the FileItem out of the request. I'm

> not entirely sure when the file is materialized, but

> it may well be at this point. Depending on how you

> have things set up you may be materializing it in

> memory and not on disk. As always, check the docs.

BabuLala at 2007-7-9 5:01:05 > top of Java-index,Java Essentials,Java Programming...
# 6

It looks like you're using an old or deprecated API. Check out the API docs. There's sample code near the top, but it's not formatted well, so you'll have to copy/paste and format it to see what it's doing.

http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/methods/multipart/MultipartRequestEntity.html

Jasprea at 2007-7-9 5:01:05 > top of Java-index,Java Essentials,Java Programming...
# 7

We are talking about the client side of the upload, aren't we? Not the server side? If so then HttpClient (and not File Uploader) is the right tool to use. The code I have for sending a file via a POST request looks like this:method.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(filePath), "text/plain"))

DrClapa at 2007-7-9 5:01:05 > top of Java-index,Java Essentials,Java Programming...
# 8

We are indeed discussing about client side of the transfer. I implemented a new client using

post.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(input), input.length()));

I can see the file contents in the Eclipse console display but file does not get created on WebLogic server and I get the following message on the server side.

<Feb 9, 2007 10:56:23 AM EST> <Warning> <netuix> <BEA-423420> <Redirect is executed in begin or refresh action. Redirect url is /console/console.portal?_nfpb=tr

ue&_pageLabel=WebAppApplicationOverviewPage&WebAppApplicationOverviewPortlethandle=com.bea.console.handles.AppDeploymentHandle%28%22com.bea%3AName%3Dvishal%2CTy

pe%3DAppDeployment%22%29.> File not found exception

How can I find out what URI that does not redirect and will work (If this is indeed the issue). Thanks much.

BabuLala at 2007-7-9 5:01:05 > top of Java-index,Java Essentials,Java Programming...