• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File upload

 
riz shahid
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this code is not working.
try {
FileItemFactory factory=new DiskFileItemFactory();
ServletFileUpload upload=new ServletFileUpload(factory);
String location="D:\tem";
File saveto=new File(location);

DiskFileItemFactory factorys=new DiskFileItemFactory();
FileItem items=null;
factorys.createItem(items.getFieldName(), items.getContentType(), false,"field1");
DiskFileItem fi=new DiskFileItem("field1", items.getContentType(), false, "mypic.png", 10000, saveto);
//MultipartFile f = new CommonsMultipartFile(fi);

} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
 
Sreelatha Sankaranarayanan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Here you have assigned items = null and in the next line you are doing items.getFieldName() , which will result in NullPointerException, you will need to initialize items before doing any operations on it.
 
riz shahid
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are right but i think fileitem save the value in binary format in any other file as like text etc but i want to save file as like image etc on my system after getting from user you have any idea about this how i can do this?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic