tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joe <l...@concrete-it.com>
Subject Re: upload and renameto apache-tomcat problem
Date Sat, 05 Apr 2003 20:16:12 GMT
hi!

i'm using the oreilly cos multipart package. it's working perfectly and 
you have the source.

see for yourself:
http://www.servlets.com/cos/index.html

joe

Peter H. wrote:

> Hello Tomcat-Community,
>
> I try to figure out a strange but reproduceable error:
> Using Apache and Tomcat under windows and maybe linux.
>
> After uploading a file to a temporary dir and renaming (moving) it
> to a apache accessible folder i have strange problems...
>
> If i upload a image with the attached servlet and after it accessing 
> the image with apache i must wait some seconds to get a succesful 
> renameTo. the problem is that if i don't create the temporary image 
> file with java the renameTo always succeeds. but the servlet should
> have file upload behaviour...
>
> maybe its the FileServletWrapper but uploading multiple times without
> accessing the image with apache there is no problem!
>
> ps. The FileServletWrapper is only available as class code...
> Any Suggestions?
>
> Thanks
> Peter
>
>
> <code>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.util.*;
>
> public final class FileServlet
> extends HttpServlet {
>
> static public final String TARGET =
> "/export/wwwdoc/test.jpg";
>
> public void service(HttpServletRequest req, HttpServletResponse resp) 
> throws IOException {
> FileServletWrapper request = new FileServletWrapper(req,
> new File("/temp"));
> File source = null;
>
> if(request.getFileParameter("file") != null) {
> source = request.ucdGetFileParameter("file").getFile();
> }
> PrintWriter writer = resp.getWriter();
> writer.write("<HTML>");
> writer.write("<BODY>");
> writer.write("<FORM NAME=\"main\" 
> ACTION=\"http://127.0.0.1/fileservlet\" METHOD=\"post\" 
> ENCTYPE=\"multipart/form-data\">");
> writer.write("<INPUT TYPE=\"file\" NAME=\"file\"/>");
> writer.write("<INPUT TYPE=\"submit\" VALUE=\"upload\"/>");
> writer.write("<hr>");
> if(source != null) {
> File target = new File(TARGET);
> if(target.exists()) {
> writer.write("Target file exists<br>");
> if(!target.delete()) {
> writer.write("Target file delete failed:" + target + "<br>");
> return;
> }
> }
> if(source.renameTo(target)) {
> writer.write("rename succeeded<br>");
> }
> else {
> writer.write("rename failed<br>");
> }
> }
> writer.write("</FORM>");
> writer.write("</BODY>");
> writer.write("</HTML>");
> }
> }
> </code>
>
>
>
> _________________________________________________________________
> Mit dem MSN Messenger eine Reise für 4 Personen nach Barcelona 
> gewinnen  jetzt mitmachen! 
> http://www.sweepstakes2003.com/entry.aspx?locationid=15
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message