Hello Kiran, I have no idea what may be going wrong and you're code looks like it is doing to much. Have you thought about extracting some methods? Do you have unit tests for the functionality? Usually I'd try to debug the code and try to find out, what's going wrong. Then I'd write a unit test that fails because of the error in the code. I'd then fix the bug so that the unit test is green. After that I would retest it in the application to see that it's now working.
You should anyway upgrade to FileUpload 1.3.1. It contains a fix for an security vulnerability. Regards, Benedikt 2014-02-26 21:15 GMT+01:00 Kiran Badi <[email protected]>: > Any comments ? > > > On Tue, Feb 25, 2014 at 9:25 PM, Kiran Badi <[email protected]> wrote: > > > Hi All, > > > > I need some help, I have below code which works perfectly file in > > localhost and does not work fully when deployed to the linux centos 5.9. > If > > I am uploading 6 images, for some reasons it upload 2 or 3 images and > > somehow believe that its overwriting the images, any suggestions as how > do > > I fix this. > > > > I have also posted this query to stackexchange, > > and link is http://stackoverflow.com/questions/22029932/apache- > > commons-file-upload-not-uploading-and-renaming-all-files > > > > and also I am on 1.2.2 version of file upload. > > > > http://stackoverflow.com/questions/22029932/apache- > > commons-file-upload-not-uploading-and-renaming-all-files > > > > } else if (!item.isFormField()) { > > long size = item.getSize(); > > String contentType = item.getContentType(); > > System.out.println("Field Name = " + > item.getFieldName() > > + ", File Name = " + item.getName() > > + ", Content type = " + item.getContentType() > > + ", File Size = " + item.getSize() > > + ", boolean isInMemory = " + > > item.isInMemory()); > > String fieldname = item.getFieldName(); > > String name = item.getName(); > > if ((fieldname.equals("img1")) && name != null) { > > if ((size < 1048576) && > (("image/jpeg".equals(contentType)) > > || ("image/jpg".equals(contentType)) || ("image/gif".equals(contentType)) > > || ("image/png".equals(contentType)) || > ("image/bmp".equals(contentType)))) > > { > > String filetype = name.substring(name. > > lastIndexOf(".")); > > ImageName = System.currentTimeMillis() + > > filetype; > > System.out.println(" ImageName1 is " + > > ImageName + "'"); > > businessfForm.setImg1(ImageName); > > } else { > > request.setAttribute("ImageError", > > ImageError); > > } > > > > } else if ((fieldname.equals("img2"))&& name != > null){ > > if ((size < 1048576) && > (("image/jpeg".equals(contentType)) > > || ("image/jpg".equals(contentType)) || ("image/gif".equals(contentType)) > > || ("image/png".equals(contentType)) || > ("image/bmp".equals(contentType)))) > > { > > String filetype = name.substring(name. > > lastIndexOf(".")); > > ImageName = System.currentTimeMillis() + > > filetype; > > System.out.println(" ImageName2 is " + > > ImageName + "'"); > > businessfForm.setImg2(ImageName); > > } else { > > request.setAttribute("ImageError", > > ImageError); > > } > > } else if ((fieldname.equals("img3"))&& name != > null) { > > if ((size < 1048576) && > (("image/jpeg".equals(contentType)) > > || ("image/jpg".equals(contentType)) || ("image/gif".equals(contentType)) > > || ("image/png".equals(contentType)) || > ("image/bmp".equals(contentType)))) > > { > > String filetype = name.substring(name. > > lastIndexOf(".")); > > ImageName = System.currentTimeMillis() + > > filetype; > > System.out.println(" ImageName3 is " + > > ImageName + "'"); > > businessfForm.setImg3(ImageName); > > } else { > > request.setAttribute("ImageError", > > ImageError); > > } > > } else if ((fieldname.equals("img4"))&& name != > null){ > > if ((size < 1048576) && > (("image/jpeg".equals(contentType)) > > || ("image/jpg".equals(contentType)) || ("image/gif".equals(contentType)) > > || ("image/png".equals(contentType)) || > ("image/bmp".equals(contentType)))) > > { > > String filetype = name.substring(name. > > lastIndexOf(".")); > > ImageName = System.currentTimeMillis() + > > filetype; > > System.out.println(" ImageName4 is " + > > ImageName + "'"); > > businessfForm.setImg4(ImageName); > > } else { > > request.setAttribute("ImageError", > > ImageError); > > } > > } else if ((fieldname.equals("img5"))&& name != > null){ > > if ((size < 1048576) && > (("image/jpeg".equals(contentType)) > > || ("image/jpg".equals(contentType)) || ("image/gif".equals(contentType)) > > || ("image/png".equals(contentType)) || > ("image/bmp".equals(contentType)))) > > { > > String filetype = name.substring(name. > > lastIndexOf(".")); > > ImageName = System.currentTimeMillis() + > > filetype; > > System.out.println(" ImageName5 is " + > > ImageName + "'"); > > businessfForm.setImg5(ImageName); > > } else { > > request.setAttribute("ImageError", > > ImageError); > > } > > } else if ((fieldname.equals("img6"))&& name != > null){ > > if ((size < 1048576) && > (("image/jpeg".equals(contentType)) > > || ("image/jpg".equals(contentType)) || ("image/gif".equals(contentType)) > > || ("image/png".equals(contentType)) || > ("image/bmp".equals(contentType)))) > > { > > String filetype = name.substring(name. > > lastIndexOf(".")); > > ImageName = System.currentTimeMillis() + > > filetype; > > System.out.println(" ImageName6 is " + > > ImageName + "'"); > > businessfForm.setImg6(ImageName); > > } else { > > request.setAttribute("ImageError", > > ImageError); > > } > > } > > File file = new File(destinationDir, ImageName); > > try { > > item.write(file); > > } catch (Exception ex) { > > > Logger.getLogger(xxx.class.getName()).log(Level.SEVERE, > > "Failed to parse upload request", ex); > > } > > } > > > -- http://people.apache.org/~britter/ http://www.systemoutprintln.de/ http://twitter.com/BenediktRitter http://github.com/britter
