cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephan Coboos <cromo...@gmx.net>
Subject Re: File upload/Multipart form
Date Fri, 23 Jan 2004 06:51:12 GMT
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


Mime
View raw message