*
The moose likes Java in General and the fly likes Problem in file uploading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem in file uploading" Watch "Problem in file uploading" New topic
Author

Problem in file uploading

Preethinj Math
Greenhorn

Joined: Mar 07, 2006
Posts: 10
Hi,

I am uploading a file into D drive,once I uploaded a file,for the 2nd time I checking a condition, whether that file exists in that directory or not?

If it does not ,then upload the file.If it exists then display a message saying "The file already exists".

My problem is when I try to upload the existing file,it does not go through the while loop at all!,so I am not able to catch the filename.

I am pasting the pieces of code.

need help please.....

//Upload.java

try{
MultiPartRequest multi = new MultiPartRequest(req,myBu.SERVERROOT+"/jsp/projects/share",5*1024*1024);
// System.out.println("After request");
out.println("<html>");
out.println("<head><title>Documents Upload...</title></head>");
out.println("<body bgcolor='#BBD7EC'>");
out.println("<h1><font color='#D02020' face='Verdana' size='4pt' ><strong>Documents Uploading...</strong></font></h1>");

out.println("<h3>The Following Document has been Uploaded successfully<h3>");
out.println("<pre align='center'>");


Enumeration files = multi.getFileNames();
while(files.hasMoreElements()){
String name = (String)files.nextElement();
String filename = multi.getFilesystemName(name);
System.out.println("filename is "+ filename);
docName = filename;
String type = multi.getContentType(name);
File f = multi.getFile(name);
//out.println("name: "+name);
out.println("<font color='#000099' face='Verdana' size='2pt' ><strong>");
out.println("Document Name : "+filename);
System.out.println("docName in Servlet :" + docName + ", fileName :" + filename + "with quotes : " + "\"" + docName + "\"" );
out.println("Document Type : "+type);

if(f != null){
out.println("Document Size : "+f.length() +" (bytes)");
}
out.println("</strong></font>");
out.println("<pre>");
}
doDML = "YES";
}
catch(Exception e){
out.println("<pre>");
e.printStackTrace(out);
out.println("</pre>");
doDML = "NO";
}



//MultipartRequest.java

else
{
if(flag1==true)
{
System.out.println("<html>");
System.out.println("<body bgcolor='#BBD7EC'>");
System.out.println("<pre align='center'>");
System.out.println("<h2><strong>File already exists</strong></h2>");//added by preethi to test
return true;
}
else
{
readAndSaveFile(in, boundary,fileName);
if (fileName.equals("unknown")){
files.put(name, new UploadedFile(null, null, null));

}
else{
files.put(name, new UploadedFile(dir.toString(),fileName, ContentType));
}
}//end of flag loop
}
return false;
}
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Do not post the same question to multiple forums; instead, Carefully Choose One Forum. I deleted the other copy of this thread.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in file uploading