cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lincoln" <linc...@linc.net.au>
Subject Re: File upload/Multipart form
Date Fri, 23 Jan 2004 07:28:39 GMT
I am trying to use the put method in an xform to put a file on the server.
As I am a newbie to forms and cocoon, should I be using your approach to get
a file on the server?

Linc

Lincoln Mitchell
hm: 618 9250 6772
mb: 0414 286 433
email: lincoln@linc.net.au
web: www.linc.net.au
----- Original Message -----
From: "Stephan Coboos" <cromosom@gmx.net>
To: <users@cocoon.apache.org>
Sent: Friday, January 23, 2004 2:51 PM
Subject: Re: File upload/Multipart form


> Lionel Crine wrote:
>
> > Here is a sample code :
> >
> > HttpServletRequest request = (HttpServletRequest)
> > objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);
> > contentType = request.getContentType();
> > if (contentType == null) {
> > contentType = parameters.getParameter("defaultContentType", null);
> > }
> > if (contentType == null) {
> > throw new Exception("ERROR");
> > } else if (contentType.startsWith("application/x-www-form-urlencoded")
> > || contentType.startsWith("multipart/form-data")) {
> > String parameter = parameters.getParameter(FORM_NAME, null);
> > if (parameter == null) {
> > throw new Exception("ERROR");
> > }
> > String sXml = request.getParameter(parameter);
> > inputSource = new InputSource(new FileInputStream(sXml));
> >
> > } else if (contentType.startsWith("text/plain") ||
> > contentType.startsWith("text/xml") ||
> > contentType.startsWith("application/xml")) {
> >
> > len = request.getContentLength();
> > if (len > 0) {
> > PostInputStream anStream = new
> > PostInputStream(request.getInputStream(), len);
> > inputSource = new InputSource(anStream);
> > } else {
> > throw new SyspeoException("ERROR);
> > }
> > } else {
> > throw new SyspeoException("ERROR);
> > }
> >
> > InputStream is = inputSource.getByteStream();
>
>
> Hello Lionel,
>
> sorry, but I don't know why you use this complicated code to realize
> uploads in cocoon. There is a solution which is very very easier!
>
> 1.) Set enable-uploads to true in web.xml.
> 2.) Get the uploaded file with
request.getAttribute("filename_on_the_form");
> 3.) After that you will receive an object of type PartOnDisk for
> example. Use getFile() to receive the uploaded file.
>
> Thats it. Isn't it easy?
>
> More informations:
> http://wiki.cocoondev.org/Wiki.jsp?page=FileUploadsWithCocoon2.1
>
> Regards
> Stephan
>
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message