commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Maxime" <max....@free.fr>
Subject Re: [FileUpload] - Need to restart each time I upload an Image
Date Sun, 10 Jul 2005 15:07:31 GMT
Hello about FireFox all is ok now,
It's just I have to put file://C:/  and it's work. But for internet things, 
I will do like that http://localhost:8080/webapps/IMG/image.jpg.
But the problem is I don't want to shutdown tomcat.
When someone upload an image throught a Form, then we can access to this 
image by a JSP.
But it doesn't work, It's look like I have to restart tomcat in order to 
take this changement (the uploaded Image).

The code is :

try{
            boolean isMultipart = FileUpload.isMultipartContent(request);

               // Create a new file upload handler
               DiskFileUpload upload = new DiskFileUpload();

               // Set upload parameters (must exploit that)
               int  yourMaxMemorySize = 512 * 1024 * 8;
               int  yourMaxRequestSize = 1024 * 1024 * 8;
               String yourTempDirectory = "C:\\TEMPO/";

               upload.setSizeThreshold(yourMaxMemorySize);
               upload.setSizeMax(yourMaxRequestSize);
               upload.setRepositoryPath(yourTempDirectory);

               //Parse the request
               List items = upload.parseRequest(request);

               // Process the uploaded items
               Iterator iter = items.iterator();
               while (iter.hasNext()) {

                   FileItem item = (FileItem) iter.next();

                   //   Process a regular form field
                   if (item.isFormField()) {
                   // Have to upgrade and do a better thing
                   if (item.getFieldName().equals("Path"))
                        {
                            Article.setItemPath(item.getString());
                        }
                        if (item.getFieldName().equals("Title"))
                        {
                            Article.setItemTitle(item.getString());
                        }
                        if (item.getFieldName().equals("Desc"))
                        {
                            Article.setItemDesc(item.getString());
                        }
                        if (item.getFieldName().equals("Price"))
                        {
                            //Article.setItemPrice(Integer.parseInt(item.getString()));
                            Article.setItemPrice(item.getString());
                        }
                        if (item.getFieldName().equals("Qty"))
                        {
                             Article.setItemQty(item.getString());

                        }

                   }

                  // Process a file upload
                  else {

                        String fieldName = item.getFieldName();
                        String fileName = item.getName();
                        //String contentType = item.getContentType();
                        //boolean isInMemory = item.isInMemory();

                        Article.setItemPath(Article.getItemPath()+"/"+fileName);

                        File uploadedFile = new File("C:\\Program 
Files/Apache Software Foundation/Tomcat 
5.0/webapps/work/web/IMG/"+Article.getItemPath());

            item.write(uploadedFile);



                  }
}

Thank you

++
Maxime

----- Original Message ----- 
From: "Dakota Jack" <dakota.jack@gmail.com>
To: "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
Sent: Sunday, July 10, 2005 3:39 PM
Subject: Re: [FileUpload] - Need to restart each time I upload an Image


There must be something wrong with your code to shut down Tomcat.
What is your code?  Firefox has not difficulties downloading files
including images.

On 7/9/05, Maxime <max.dev@free.fr> wrote:
> Hello,
> I made a form where we can upload an Image on the tomcat Server.
> But the problem is Tomcat must be restarted in order to take this 
> changement (the uploaded Image).
> Is there any way or trick to avoid that ? (or some code for automatic 
> restart each time I upload an image).
> I could define the local path ( C:/..... image.jpg ) , but I don't know 
> why it's doesn't work on FireFox browser (it does work on IE).
>
> I am using windows XP SP 2 for testing the code, Tomcat 5.0.28 and Java 
> 1.5.0.0_4.
>
> Thank you very much !
>
> Maxime
>


-- 
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

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



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


Mime
View raw message