0

I am sending this request on servlet from client side:

at client side I'm doing: img = Capture.capturePhoto(200, 200);

        InfiniteProgress inf = new InfiniteProgress();            
        Dialog progress = inf.showInifiniteBlocking(); 
        MultipartRequest request = new MultipartRequest();

        request.setUrl("http://localhost:8080/Test/Test");//calling servlet

          request.addData("ImageName.jpg", img, "image/jpeg");
          request.addArgument("imgname", "image1");


        request.setDisposeOnCompletion(progress);
        NetworkManager.getInstance().addToQueue(request);

On the server side I'm using this:

a = req.getParameter("imgname");// but value I'm getting is null 
File repository = new File ("F:/SERVLET images");
System.out.println(repository);
DiskFileItemFactory factory = new DiskFileItemFactory(1024, repository);
((DiskFileItemFactory) factory).setRepository(repository);
ServletFileUpload upload = new ServletFileUpload(factory);

try
{
    items = upload.parseRequest(req);
}
catch (FileUploadException e)
{
    // TODO Auto-generated catch block
    e.printStackTrace();
}
Iterator<FileItem> iter = items.iterator();
while (iter.hasNext())
{
    FileItem item = iter.next();
    File f1 = new File ("F:/SERVLET images/pics/'"+a+"'.jpg");
    // 'null'.jpg is Printing and image is not displaying   
    try
    {
        item.write(f1);
        System.out.print(f1);
    }
}

What did I get wrong?

Diksha
  • 1
  • 1
  • 2
    Give details about what issue you are getting (Exception or what) – Prabhaker A Jul 21 '13 at 07:15
  • Yeah, what is the issue? What isn't working? – tbodt Jul 21 '13 at 07:18
  • are you trying to upload file from browser? – M Sach Jul 21 '13 at 07:21
  • 1
    The way you handle parameters is completely wrong (line 1). Read the documentation, section 'Processing the uploaded items': http://commons.apache.org/proper/commons-fileupload/using.html – home Jul 21 '13 at 07:25
  • Basically I'm using Codename one for mobile application, the problem I'm facing is getting null value on server side. – Diksha Jul 22 '13 at 05:03
  • Problem is not with image uploading, when I'm doing File f1 = new File ("F:/SERVLET images/pics/img.jpg"); It's working Fine . But I want to getParameter from user. I think I'm getting wrong with method . – Diksha Jul 22 '13 at 07:29

0 Answers0