Fellow Magnolia Users,

Has anyone had any success using the Jakarta Commons FileUpload library with 
Magnolia.  I am using Magnolia 2.1 with the standard version of Tomcat that 
came with it.  I can get a file to successfully upload when I put my 
uploadForm.jsp and upload.jsp in the ROOT webapps folder, but when I put it 
anywhere inside the magnolia author area the files in the multipart request 
are not found when it has been parsed.  It almost seem like it is getting a 
different type of request alltogether when displaying magnolia pages than it 
is when the JSP is running as a basic tomcat one.

What I am trying to do is add a file upload tab to admincentral in order to 
give my authors a place to upload pdfs, docs, ppts, etc to a centralized 
place.  Basically, so that they can change their files in one place and have 
those changes reflected in all the pages that link to these documents.  I 
have modified the adminCentral menu to incorporate the button and it 
basically just sticks a JSP of my choosing in that right iframe.

Here is uploadForm.jsp:

<jsp:root version="1.2" xmlns:jsp = "http://java.sun.com/JSP/Page";>
        <jsp:directive.page contentType="text/html; charset=UTF-8" />
        <![CDATA[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";> ]]>
        <html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
                <head>
                        <title>File Upload</title>
                        <meta http-equiv="Content-Type" content="text/html; 
charset=UTF-8" />
                </head>
                <body>
                        <h1>File Upload</h1>
                        <h2>Upload files to a centralized location</h2>
                        <hr/>
                        <form method="post" action="upload.jsp" 
enctype="multipart/form-data">
                                Name: <input type="text" name="uname"/>
                                File: <input type="file" name="upfile"/>
                                <input type="submit"/>
                        </form>
                </body>
        </html>
</jsp:root>

Here is upload.jsp:

<jsp:root version="1.2" xmlns:jsp = "http://java.sun.com/JSP/Page";>
        <jsp:directive.page import="org.apache.commons.fileupload.*"/>
        <jsp:directive.page import="java.io.File" />
        <jsp:directive.page import="java.util.*" />
        <jsp:directive.page contentType="text/html; charset=UTF-8" />
        <![CDATA[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";> ]]>
        <html>
        <head><title>Upload Result</title></head>
                <body>
                        <jsp:scriptlet>
                                <![CDATA[
                                        try {
                                                out.println("<p>request = " + 
request.getClass().toString() + "</p>");
                                                FileUpload fup=new FileUpload();
                                                boolean isMultipart = 
FileUpload.isMultipartContent(request);
                                                out.println("<p>request has 
multipart = " + isMultipart + "</p>");
                                                // Create a new file upload 
handler
                                                DiskFileUpload upload = new 
DiskFileUpload();
                                                // Parse the request
                                                List items = 
upload.parseRequest(request);
                                                Iterator iter = 
items.iterator();
                                                if (!iter.hasNext()) {
                                                        out.println("<p>no 
request info found!</p>");
                                                }
                                                while (iter.hasNext()) {
                                                        FileItem item = 
(FileItem) iter.next();
                                                        if (item.isFormField()) 
{
                                                                
out.println("<p>found a field: " + item.getString() + "</p>");
                                                        } else {
                                                                
out.print("<p>found a file: " + item.getName());
                                                                File cfile = 
new File(item.getName());
                                                                File tosave = 
new File(getServletContext().getRealPath("/") + 
"fileupload/dumpage/",cfile.getName());
                                                                
item.write(tosave);
                                                        }
                                                }
                                                
out.println("<p><strong>done.</strong></p>");
                                        } catch (Exception e){
                                                System.out.println(e);
                                        }
                                ]]>
                        </jsp:scriptlet>
                </body>
        </html>
</jsp:root>

Here is the output when I view the JSP in 
%tomcat_dir%/webapps/ROOT/fileupload/

        request = class org.apache.coyote.tomcat5.CoyoteRequestFacade
        request has multipart = true
        found a field: meh
        found a file: ATM_POS_Map.jpg
        done.

As you can see it parses the request fine and finds the file.  It gets it and 
everything is absolutely lovey dovey.

Here is the output when I view the JSP in 
%tomcat_dir%/webapps/author/admintemplates/fileupload/
(note: I have a virtualuri mapper pointing 
from /.magnolia/fileupload/uploadForm.html 
to /admintemplates/fileupload/uploadForm.jsp
and from /.magnolia/fileupload/uploadForm.html 
to /admintemplates/fileupload/upload.jsp)

        request = class org.apache.catalina.core.ApplicationHttpRequest
        pageContext.request = class 
org.apache.catalina.core.ApplicationHttpRequest
        request has multipart = true
        no request info found!
        done.

No such luck here.  

Can anyone enlighten me as to why the class types for the two HttpRequests are 
different and if there is any way to get hold of the original request? I 
profusely apologize for the longwinded email.  Thanks in advance to any help 
you guys can offer.  If you don't have a copy of the Jarkarta Commons 
FileUpload library and would like to take a crack at this, it can be obtained 
here: http://jakarta.apache.org/commons/fileupload/

Regards,
Adam Cooper
Talisen Technologies
[EMAIL PROTECTED]




----------------------------------------------------------------
for list details see
http://www.magnolia.info/en/magnolia/developer.html
----------------------------------------------------------------

Reply via email to