cancel
Showing results for 
Search instead for 
Did you mean: 

File is not a normal file exception while using HttpClient()

SandipAgarwalla
Active Contributor
0 Kudos

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

Accepted Solutions (0)

Answers (3)

Answers (3)

SandipAgarwalla
Active Contributor
0 Kudos

closing the thread..

Former Member
0 Kudos

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

SandipAgarwalla
Active Contributor
0 Kudos

Hi Vivek,

I tried with this also. But still the same exception of File is not a normal file.

Regards

Sandip

Former Member
0 Kudos

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

SandipAgarwalla
Active Contributor
0 Kudos

Hi Vivek,

I am trying with single file upload only.

Can you pls point out that sample code in apache.

Regards

Sandip