Hi Marco & Jan ... I'm trying to implement an upload files action under Cocoon 2.1.
In Cocoon 2.1., you should use Part instead of FilePart > FilePart filePart = (FilePart) request.get(paramName); But ... what about FilePartFile ??? Which is the equivalent for Cocoon 2.1??? > File file = ( (FilePartFile) filePart).getFile(); Thanks ----- Original Message ----- From: "Marco Rolappe" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, November 13, 2003 2:47 PM Subject: AW: File upload > hi jan, > > > > -----Ursprüngliche Nachricht----- > > Von: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] > > Auftrag von Jan Wielgus > > Gesendet: Donnerstag, 13. November 2003 10:15 > > An: [EMAIL PROTECTED] > > Betreff: File upload > > > > > > Hello, > > > > I would like to get the file upload working with cocoon 2.1, but > > unfortunately the examples in wiki don't give enough for such newbie > > as me :( In the wikipage about upload with flow written by Geoff > > Howard there are two possibilities showed. The first one, with > > JavaScript contains the following line: > > > > var role = Packages.org.mystuff.UploadManager.ROLE; > > > > The problem is, I don't know, where I should take the ROLE object > > from? I actually get stuck at this moment, when I want to do > > something here... > > the UploadManager in this example is a custom (Avalon) component. if you > don't know about Avalon components, containers, roles, etc. you might want > to read about that first (that is, if you want to go the component way). > > > The second possibility says "Alternatively, you can write the > > following java code in your sitemap components". What does it > > actually mean here? An Action? If yes, is it possible to get the > > complete code of that action? > > > > Or maybe someone has a working example of a file upload? Any help > > would be really appreciated. > > following short example is for cocoon 2.0.4, but I guess it should also work > for 2.1.x: > > ... > public class MyUploadAction > extends AbstractLogEnabled > implements Action > { > > /* (non-Javadoc) > * @see > org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector > , org.apache.cocoon.environment.SourceResolver, java.util.Map, > java.lang.String, org.apache.avalon.framework.parameters.Parameters) > */ > public Map act( > Redirector redirector, > SourceResolver resolver, > Map objectModel, > String source, > Parameters par) > throws ParameterException > { > // the action parameter 'parameter-name' specifies the request parameter > name the uploaded file is bound to > String > paramName = par.getParameter("parameter-name"); > > // get the request > Request > request = ObjectModelHelper.getRequest(objectModel); > > // get the FilePart (handle to the file) from the request parameter > FilePart > filePart = (FilePart) request.get(paramName); > > // ok, file was successfully uploaded > if (filePart != null) > { > // get the file > File > file = ( (FilePartFile) filePart).getFile(); > > getLogger ().debug ("uploaded file: " + file); > > // signal 'success' to sitemap > return (Collections.EMPTY_MAP); > } > else > { > getLogger ().warn ("upload failed"); > > // signal 'failure' to sitemap > return (null); > } > } > } > ... > > > for uploads to work (correctly), some things have to be configured, most > importantly a supporting RequestFactory, e.g. the MultiPartRequestFactory. > have a look at web.xml: > > ... > <!-- > This parameter allows you to select the request factory. Possible choices > are as follows: > - org.apache.cocoon.components.request.MultipartRequestFactoryImpl > - org.apache.cocoon.components.request.MaybeUploadRequestFactoryImpl > --> > <init-param> > <param-name>request-factory</param-name> > > <param-value>org.apache.cocoon.components.request.MultipartRequestFactoryImp > l</param-value> > </init-param> > ... > > > then have a form post to an URL: > > ... > <form action="upload" method="post" enctype="multipart/form-data"> > <input type="file" name="my-uploaded-file"/> > <br/> > > <input type="submit"/> > </form> > ... > > > and handle the request in your sitemap: > > ... > <map:match pattern="upload"> > <map:act type="upload"> > <map:parameter name="parameter-name" value="my-uploaded-file"/> > </map:act> > </map:match> > ... > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
