cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geoff Howard <coc...@leverageweb.com>
Subject Re: Multipart form upload
Date Fri, 06 Feb 2004 00:45:15 GMT
Chris Wilder-Smith wrote:

> On Thu, 2004-02-05 at 17:23, Geoff Howard wrote:
> 
>>Chris Wilder-Smith wrote:

snip the sanity check stuff.  all sounds right.

>>4) Did you say you were getting a HttpRequest?  That brings up a change 
>>to the Request stored in the objectModel which may make that code on the 
>>wiki no longer work as written.  Try this:
>>
>>Request request = ObjectModelHelper.getRequest(obj);
>>Object o = request.get("blah");
>>if (o == null) {
>>   // parameter missing from request
>>} else if (o instanceof Part) {
>>   Part part = (Part) o;
>>   // do something with it
>>} else if (o instanceof String) {
>>   // upload is disabled - I think.
>>}
> 
> 
> this is basically what I'm doing.  When I print out something like this:
> 
> System.err.println("  ** request class: " + 
>      "request.getClass().getName());
> 
> I get
> 
>  ** request class: org.apache.cocoon.environment.http.HttpRequest

Right - and that's the point.  Sorry I didn't explain more, but a change 
was made to the environment and request abstraction handling such that 
the assumption in the wiki that you can tell whether uploads are 
successfully enabled is no longer correct.

So, you'll notice in my proposed code that I ignore the type of request. 
   Try it and let me know what happens.  If you just println inside each 
condition block you'll have a major clue.

> I'm assuming that request.get(str) is functionally different from
> request.getAttribute(str) - is there an equivalent to
> request.getAtrributeNames() - I would like to verify that I'm not just
> doing something stupid, like using the wrong key on the 'get'. I'll go
> dig through the source.

First, don't confuse request attributes with parameters.  Parameters are 
the things that come in via GET or POST.  But yes, there is an imporant 
difference.  Use getParameter(String key) to get at normal string 
parameters.  get(String key) returns Object and so has to be used to get 
at uploaded Files which have been parsed by Cocoon and added to the 
request parameter collection as Part objects.  Use Enumeration 
request.getParameterNames() (not request.getAttributeNames()! ) if you 
want to check that the field is present at all.

Geoff

>>>On Thu, 2004-02-05 at 16:35, Geoff Howard wrote:
>>>
>>>
>>>>Chris Wilder-Smith wrote:
>>>>
>>>>
>>>>>Hi,
>>>>>
>>>>>We're trying to use a multipart/form-data post to upload audio files
>>>>>recorded on the client machine to our cocoon-based backend. All of the
>>>>>web.xml file upload params seem to be set correctly:
>>>>>
>>>>>request-factory=org.apache.cocoon.components.request.MultipartRequestFactoryImpl
>>>>>enable-uploads=true
>>>>>upload-directory=WEB-INF/work/upload-dir
>>>>>autosave-uploads=true
>>>>>overwrite-uploads=rename
>>>>>upload-max-size=10000000
>>>>>
>>>>>
>>>>>According to the wiki pages, I should see the request type as
>>>>>MultipartHttpServletRequest when it comes through, but it is a regular
>>>>>cocoon HttpRequest.  According to the example, this implies that uploads
>>>>>still aren't enabled.
>>>>>
>>>>>I do see other parameters that come through on the request, it's picking
>>>>>up the correct generator, etc.
>>>>
>>>>Which Cocoon version, which wiki page?
>>>>
>>>>Geoff


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


Mime
View raw message