This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes File upload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "File upload" Watch "File upload" New topic
Author

File upload

riz shahid
Greenhorn

Joined: Feb 02, 2011
Posts: 2
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

Joined: Dec 10, 2010
Posts: 9


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

Joined: Feb 02, 2011
Posts: 2
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File upload
 
Similar Threads
File Upload
problem regarding File Uploading on Server.
getting nullPointerException on line upload.parseRequest(request);
getting the uploaded filename for downloading
upload.parseRequest(request); giving null.