You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Robert Kromkamp <ro...@emaxx.nl> on 2003/07/15 09:23:09 UTC

upload problem

Hi,

I'm trying to upload an image with Cocoon. But when i'm trying to read the
parameters of the file in my Action it seems to be an String. What did I do
wrong?

I've the following form:

addresidence.xml
===================
<form action="addresidence.html" enctype="multipart/form-data">
    <tr>
        <td>
            <input type="file" name="uploadfile" size="50"/>
            <input type="submit"/>
        </td>
    </tr>
</form>
===================



web.xml
===================
    <init-param>
      <param-name>enable-uploads</param-name>
      <param-value>true</param-value>
    </init-param>
===================



myAction.java (extends AbstractXMLFormAction implements FormListener)
===================
import org.apache.cocoon.acting.AbstractXMLFormAction;
import org.apache.cocoon.components.xmlform.Form;
import org.apache.cocoon.components.xmlform.FormListener;
import org.apache.cocoon.servlet.multipart.Part;

.....


HashMap parameters = new HashMap();

Enumeration parametersEnum = getRequest().getParameterNames();
System.out.println("Voor de while");
while( parametersEnum.hasMoreElements() ){
    String name = (String)parametersEnum.nextElement();
    Object value = getRequest().getParameter( name );

    System.out.println("Voor instanceof");
    System.out.println("instance of: "+value.getClass().getName());
    System.out.println("instance package: "+value.getClass().getPackage());
    System.out.println("instance to string: "+value.toString());
    if (value instanceof Part) {
       System.out.println("Part");
    }
    parameters.put( name, value );
}

===================




sitemap.xmap
===================

<map:pipeline>
    <map:match pattern="">
         <map:redirect-to uri="overview.html"/>
    </map:match>

    <map:match pattern="wml/">
        <map:redirect-to uri="../overview.wml"/>
    </map:match>

    <map:match pattern="overview.html">
        <map:read src="overview.html"/>
    </map:match>

    <map:match pattern="overview.wml">
        <map:read src="overview.wml"/>
    </map:match>

    <map:match pattern="img/*.gif">
        <map:read src="img/{1}.gif" mime-type="image/gif"  />
    </map:match>

    <map:match pattern="img/*.jpg">
        <map:read src="img/{1}.jpg" mime-type="image/jpg"  />
    </map:match>

    <map:match pattern="stylesheets/css/*.css">
        <map:read src="stylesheets/css/{1}.css" mime-type="text/css "  />
    </map:match>
</map:pipeline>

<map:pipeline>
  <map:match pattern="addresidence.*">
	<map:act type="request">
      	<map:parameter name="parameters" value="true"/>
            <map:act type="MyAction">
			<map:generate src="upload.html"/>
			<map:serialize type="html" label="debug"/>
		</map:act>
      </map:act>
  </map:match>
</map:pipeline>
===================


I get the following output of my program:
-----
Voor de while
Voor instanceof
instance of: java.lang.String
instance package: package java.lang, Java Platform API Specification,
version 1.4
instance to string:
C:\jakarta-tomcat-4.1.12\work\Standalone\localhost\forms\cocoon-files\upload
-dir\group-logo.gif
-----

As you can see it's an instance of a String, but I expected an instance of a
Part. Can someone explain this?

When I look in the directory
C:\jakarta-tomcat-4.1.12\work\Standalone\localhost\forms\cocoon-files\upload
-dir\ there's no file available. What do I do wrong? Has it something to
with AbstractXMLFormAction? I'm deploying under tomcat. Do I've to change
some settings of it?

Many thanks for your time!

Kind regards,
Robert Kromkamp



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: upload problem

Posted by Geoff Howard <co...@leverageweb.com>.
Robert Kromkamp wrote:
> Thanks for your advice, I've changed it, but i still don't get a file. Ik
> think the problem is there's no file in the directory
> C;\jakarta-tomcat-4.1.12\work\Standalone\localhost\forms\cocoon-files\upload
> . Should it be there?

By default, Cocoon (2.1) removes the file from the upload dir at the end 
of the request, so you won't necessarily see it there.  You can change 
that behavior with autosave-uploads in web.xml.

Does your System.out report a Part object?

If so, then the problem is in what happens from there - you put it a 
HashMap but what from there?

If not, you may be looking in the wrong "Request".  What does 
getRequest() do/return? (not familiar with AbstractXMLFormAction if it's 
inherited).  You may also want to double check that you edited the right 
web.xml and that the changes did not get overwritten since.  BTW, if you 
are building from cvs there is a build property you can set with 
local.build.properties to turn on uploads in a way that survives a 
re-build.  It's run by the custom-conf (customconf?) target and 
documented at the wiki under xpatch task usage.

Geoff

> -----Original Message-----
> From: Geoff Howard [mailto:cocoon@leverageweb.com]
> Sent: dinsdag 15 juli 2003 15:43
> To: users@cocoon.apache.org
> Subject: Re: upload problem
> 
> 
> See the corrected line below in your action:
> 
> Robert Kromkamp wrote:
> 
>>Hi,
>>
>>I'm trying to upload an image with Cocoon. But when i'm trying to read the
>>parameters of the file in my Action it seems to be an String. What did I
> 
> do
> 
>>wrong?
>>
>>I've the following form:
>>
>>addresidence.xml
>>===================
>><form action="addresidence.html" enctype="multipart/form-data">
>>    <tr>
>>        <td>
>>            <input type="file" name="uploadfile" size="50"/>
>>            <input type="submit"/>
>>        </td>
>>    </tr>
>></form>
>>===================
>>
>>
>>
>>web.xml
>>===================
>>    <init-param>
>>      <param-name>enable-uploads</param-name>
>>      <param-value>true</param-value>
>>    </init-param>
>>===================
>>
>>
>>
>>myAction.java (extends AbstractXMLFormAction implements FormListener)
>>===================
>>import org.apache.cocoon.acting.AbstractXMLFormAction;
>>import org.apache.cocoon.components.xmlform.Form;
>>import org.apache.cocoon.components.xmlform.FormListener;
>>import org.apache.cocoon.servlet.multipart.Part;
>>
>>.....
>>
>>
>>HashMap parameters = new HashMap();
>>
>>Enumeration parametersEnum = getRequest().getParameterNames();
>>System.out.println("Voor de while");
>>while( parametersEnum.hasMoreElements() ){
>>    String name = (String)parametersEnum.nextElement();
>>    Object value = getRequest().getParameter( name );
> 
> 
> No, getParameter returns a String.  you need:
> 
>    Object value = getRequest().get(name);
> 
> 
>>    System.out.println("Voor instanceof");
>>    System.out.println("instance of: "+value.getClass().getName());
>>    System.out.println("instance package:
> 
> "+value.getClass().getPackage());
> 
>>    System.out.println("instance to string: "+value.toString());
>>    if (value instanceof Part) {
>>       System.out.println("Part");
>>    }
>>    parameters.put( name, value );
>>}
>>
>>===================
>>
>>
>>
>>
>>sitemap.xmap
>>===================
>>
>><map:pipeline>
>>    <map:match pattern="">
>>         <map:redirect-to uri="overview.html"/>
>>    </map:match>
>>
>>    <map:match pattern="wml/">
>>        <map:redirect-to uri="../overview.wml"/>
>>    </map:match>
>>
>>    <map:match pattern="overview.html">
>>        <map:read src="overview.html"/>
>>    </map:match>
>>
>>    <map:match pattern="overview.wml">
>>        <map:read src="overview.wml"/>
>>    </map:match>
>>
>>    <map:match pattern="img/*.gif">
>>        <map:read src="img/{1}.gif" mime-type="image/gif"  />
>>    </map:match>
>>
>>    <map:match pattern="img/*.jpg">
>>        <map:read src="img/{1}.jpg" mime-type="image/jpg"  />
>>    </map:match>
>>
>>    <map:match pattern="stylesheets/css/*.css">
>>        <map:read src="stylesheets/css/{1}.css" mime-type="text/css "  />
>>    </map:match>
>></map:pipeline>
>>
>><map:pipeline>
>>  <map:match pattern="addresidence.*">
>>	<map:act type="request">
>>      	<map:parameter name="parameters" value="true"/>
>>            <map:act type="MyAction">
>>			<map:generate src="upload.html"/>
>>			<map:serialize type="html" label="debug"/>
>>		</map:act>
>>      </map:act>
>>  </map:match>
>></map:pipeline>
>>===================
>>
>>
>>I get the following output of my program:
>>-----
>>Voor de while
>>Voor instanceof
>>instance of: java.lang.String
>>instance package: package java.lang, Java Platform API Specification,
>>version 1.4
>>instance to string:
>>
> 
> C:\jakarta-tomcat-4.1.12\work\Standalone\localhost\forms\cocoon-files\upload
> 
>>-dir\group-logo.gif
>>-----
>>
>>As you can see it's an instance of a String, but I expected an instance of
> 
> a
> 
>>Part. Can someone explain this?
>>
>>When I look in the directory
>>
> 
> C:\jakarta-tomcat-4.1.12\work\Standalone\localhost\forms\cocoon-files\upload
> 
>>-dir\ there's no file available. What do I do wrong? Has it something to
>>with AbstractXMLFormAction? I'm deploying under tomcat. Do I've to change
>>some settings of it?
>>
>>Many thanks for your time!
>>
>>Kind regards,
>>Robert Kromkamp


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: upload problem

Posted by Robert Kromkamp <ro...@emaxx.nl>.
Thanks for your advice, I've changed it, but i still don't get a file. Ik
think the problem is there's no file in the directory
C;\jakarta-tomcat-4.1.12\work\Standalone\localhost\forms\cocoon-files\upload
. Should it be there?

Cheers,
Robert

-----Original Message-----
From: Geoff Howard [mailto:cocoon@leverageweb.com]
Sent: dinsdag 15 juli 2003 15:43
To: users@cocoon.apache.org
Subject: Re: upload problem


See the corrected line below in your action:

Robert Kromkamp wrote:
> Hi,
>
> I'm trying to upload an image with Cocoon. But when i'm trying to read the
> parameters of the file in my Action it seems to be an String. What did I
do
> wrong?
>
> I've the following form:
>
> addresidence.xml
> ===================
> <form action="addresidence.html" enctype="multipart/form-data">
>     <tr>
>         <td>
>             <input type="file" name="uploadfile" size="50"/>
>             <input type="submit"/>
>         </td>
>     </tr>
> </form>
> ===================
>
>
>
> web.xml
> ===================
>     <init-param>
>       <param-name>enable-uploads</param-name>
>       <param-value>true</param-value>
>     </init-param>
> ===================
>
>
>
> myAction.java (extends AbstractXMLFormAction implements FormListener)
> ===================
> import org.apache.cocoon.acting.AbstractXMLFormAction;
> import org.apache.cocoon.components.xmlform.Form;
> import org.apache.cocoon.components.xmlform.FormListener;
> import org.apache.cocoon.servlet.multipart.Part;
>
> .....
>
>
> HashMap parameters = new HashMap();
>
> Enumeration parametersEnum = getRequest().getParameterNames();
> System.out.println("Voor de while");
> while( parametersEnum.hasMoreElements() ){
>     String name = (String)parametersEnum.nextElement();
>     Object value = getRequest().getParameter( name );

No, getParameter returns a String.  you need:

   Object value = getRequest().get(name);

>
>     System.out.println("Voor instanceof");
>     System.out.println("instance of: "+value.getClass().getName());
>     System.out.println("instance package:
"+value.getClass().getPackage());
>     System.out.println("instance to string: "+value.toString());
>     if (value instanceof Part) {
>        System.out.println("Part");
>     }
>     parameters.put( name, value );
> }
>
> ===================
>
>
>
>
> sitemap.xmap
> ===================
>
> <map:pipeline>
>     <map:match pattern="">
>          <map:redirect-to uri="overview.html"/>
>     </map:match>
>
>     <map:match pattern="wml/">
>         <map:redirect-to uri="../overview.wml"/>
>     </map:match>
>
>     <map:match pattern="overview.html">
>         <map:read src="overview.html"/>
>     </map:match>
>
>     <map:match pattern="overview.wml">
>         <map:read src="overview.wml"/>
>     </map:match>
>
>     <map:match pattern="img/*.gif">
>         <map:read src="img/{1}.gif" mime-type="image/gif"  />
>     </map:match>
>
>     <map:match pattern="img/*.jpg">
>         <map:read src="img/{1}.jpg" mime-type="image/jpg"  />
>     </map:match>
>
>     <map:match pattern="stylesheets/css/*.css">
>         <map:read src="stylesheets/css/{1}.css" mime-type="text/css "  />
>     </map:match>
> </map:pipeline>
>
> <map:pipeline>
>   <map:match pattern="addresidence.*">
> 	<map:act type="request">
>       	<map:parameter name="parameters" value="true"/>
>             <map:act type="MyAction">
> 			<map:generate src="upload.html"/>
> 			<map:serialize type="html" label="debug"/>
> 		</map:act>
>       </map:act>
>   </map:match>
> </map:pipeline>
> ===================
>
>
> I get the following output of my program:
> -----
> Voor de while
> Voor instanceof
> instance of: java.lang.String
> instance package: package java.lang, Java Platform API Specification,
> version 1.4
> instance to string:
>
C:\jakarta-tomcat-4.1.12\work\Standalone\localhost\forms\cocoon-files\upload
> -dir\group-logo.gif
> -----
>
> As you can see it's an instance of a String, but I expected an instance of
a
> Part. Can someone explain this?
>
> When I look in the directory
>
C:\jakarta-tomcat-4.1.12\work\Standalone\localhost\forms\cocoon-files\upload
> -dir\ there's no file available. What do I do wrong? Has it something to
> with AbstractXMLFormAction? I'm deploying under tomcat. Do I've to change
> some settings of it?
>
> Many thanks for your time!
>
> Kind regards,
> Robert Kromkamp


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: upload problem

Posted by Geoff Howard <co...@leverageweb.com>.
See the corrected line below in your action:

Robert Kromkamp wrote:
> Hi,
> 
> I'm trying to upload an image with Cocoon. But when i'm trying to read the
> parameters of the file in my Action it seems to be an String. What did I do
> wrong?
> 
> I've the following form:
> 
> addresidence.xml
> ===================
> <form action="addresidence.html" enctype="multipart/form-data">
>     <tr>
>         <td>
>             <input type="file" name="uploadfile" size="50"/>
>             <input type="submit"/>
>         </td>
>     </tr>
> </form>
> ===================
> 
> 
> 
> web.xml
> ===================
>     <init-param>
>       <param-name>enable-uploads</param-name>
>       <param-value>true</param-value>
>     </init-param>
> ===================
> 
> 
> 
> myAction.java (extends AbstractXMLFormAction implements FormListener)
> ===================
> import org.apache.cocoon.acting.AbstractXMLFormAction;
> import org.apache.cocoon.components.xmlform.Form;
> import org.apache.cocoon.components.xmlform.FormListener;
> import org.apache.cocoon.servlet.multipart.Part;
> 
> .....
> 
> 
> HashMap parameters = new HashMap();
> 
> Enumeration parametersEnum = getRequest().getParameterNames();
> System.out.println("Voor de while");
> while( parametersEnum.hasMoreElements() ){
>     String name = (String)parametersEnum.nextElement();
>     Object value = getRequest().getParameter( name );

No, getParameter returns a String.  you need:

   Object value = getRequest().get(name);

> 
>     System.out.println("Voor instanceof");
>     System.out.println("instance of: "+value.getClass().getName());
>     System.out.println("instance package: "+value.getClass().getPackage());
>     System.out.println("instance to string: "+value.toString());
>     if (value instanceof Part) {
>        System.out.println("Part");
>     }
>     parameters.put( name, value );
> }
> 
> ===================
> 
> 
> 
> 
> sitemap.xmap
> ===================
> 
> <map:pipeline>
>     <map:match pattern="">
>          <map:redirect-to uri="overview.html"/>
>     </map:match>
> 
>     <map:match pattern="wml/">
>         <map:redirect-to uri="../overview.wml"/>
>     </map:match>
> 
>     <map:match pattern="overview.html">
>         <map:read src="overview.html"/>
>     </map:match>
> 
>     <map:match pattern="overview.wml">
>         <map:read src="overview.wml"/>
>     </map:match>
> 
>     <map:match pattern="img/*.gif">
>         <map:read src="img/{1}.gif" mime-type="image/gif"  />
>     </map:match>
> 
>     <map:match pattern="img/*.jpg">
>         <map:read src="img/{1}.jpg" mime-type="image/jpg"  />
>     </map:match>
> 
>     <map:match pattern="stylesheets/css/*.css">
>         <map:read src="stylesheets/css/{1}.css" mime-type="text/css "  />
>     </map:match>
> </map:pipeline>
> 
> <map:pipeline>
>   <map:match pattern="addresidence.*">
> 	<map:act type="request">
>       	<map:parameter name="parameters" value="true"/>
>             <map:act type="MyAction">
> 			<map:generate src="upload.html"/>
> 			<map:serialize type="html" label="debug"/>
> 		</map:act>
>       </map:act>
>   </map:match>
> </map:pipeline>
> ===================
> 
> 
> I get the following output of my program:
> -----
> Voor de while
> Voor instanceof
> instance of: java.lang.String
> instance package: package java.lang, Java Platform API Specification,
> version 1.4
> instance to string:
> C:\jakarta-tomcat-4.1.12\work\Standalone\localhost\forms\cocoon-files\upload
> -dir\group-logo.gif
> -----
> 
> As you can see it's an instance of a String, but I expected an instance of a
> Part. Can someone explain this?
> 
> When I look in the directory
> C:\jakarta-tomcat-4.1.12\work\Standalone\localhost\forms\cocoon-files\upload
> -dir\ there's no file available. What do I do wrong? Has it something to
> with AbstractXMLFormAction? I'm deploying under tomcat. Do I've to change
> some settings of it?
> 
> Many thanks for your time!
> 
> Kind regards,
> Robert Kromkamp


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org