on 07-17-2007 11:26 PM
Hi All,
I would like to upload few files from the end user desktop machine to a unix server. This process will be done during the execution of a portal application (PAR). I was just trying my hands at the following code, but it gives me <b>File is not a normal file exception</b>.
****
public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
{
response.write("Hi Sandip.....");
/** reading file informations */
final String serverURL = "serverURL";
PostMethod mPost=null;
try {
HttpClient httpCl = new HttpClient();
mPost = new PostMethod(serverURL);
File file1 = new File("D:\JavaScreen.jpeg");
response.write("<BR>you selected the file::"+file1.getAbsolutePath());
mPost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE,true);
response.write("<BR>Uploading file to server....");
//Part fileParts = new FilePart(file1.getName(),file1);
FilePart[] filePart = {
new FilePart(file1.getName(),file1) //add multiple files here
};
mPost.setRequestEntity(new MultipartRequestEntity(filePart,mPost.getParams()));
httpCl.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
int statusCode = httpCl.executeMethod(mPost);
if(statusCode==HttpStatus.SC_OK){
response.write("<BR>upload done:"+mPost.getResponseBodyAsString());
}else{
response.write("<BR>upload failed:"+HttpStatus.getStatusText(statusCode));
}
mPost.releaseConnection();
} catch (HttpException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
response.write("Excp1:"+e.getLocalizedMessage());
mPost.releaseConnection();
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace()
response.write("Excp2:"+e.getLocalizedMessage());
response.write("Excp3::"+e.getCause());
mPost.releaseConnection();
}finally{
mPost.releaseConnection();
}
****
This is written inside a portal application. While running this code, it gives an output
Hi Sandip.....
you selected the file::D:JavaScreen.jpeg
Uploading file to server....Excp2:File is not a normal file.Excp3::null
What could be the problem? I tried with 2-3 files.
Would appreciate a reply.
Regards
Sandip Agarwal
closing the thread..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
you can check this link.
<a href="http://svn.apache.org/viewvc/jakarta/httpcomponents/oac.hc3x/trunk/src/examples/">HttpClient sample codes</a>
regards
Vivek Nidhi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I have tried this before, first please try with single file upload.
there is some sample code at apache site, it was working fine for me
regards
Vivek Nidhi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.