Re: Doubt about file upload in Cocoon 2.2

Javier Puerto <[email protected]>
Newsgroups gmane.text.xml.cocoon.user
Message-ID <CAACZMNfwMC67-g7GqQaEpRPjL74uTKqcESh9R4B2aO4NUXoksA@mail.gmail.com>
Hola Miguel,


2013/6/6 Miguel <[email protected]>

> Hi
>
>   At present, I work on project based on cocoon 2.2 and I want to use file
> upload option to send an email with cocoon. Documentation of cocoon
> indicates about the parameters:
>
> org.apache.cocoon.uploads.**enable=true
> org.apache.cocoon.uploads.**autosave=true
> org.apache.cocoon.uploads.**maxsize=10000000
>
> The last parameter is very interesting because limit the size of files to
> upload the platform, so I think cocoon would be safe if people try upload
> ver big files.
>
> I have checked that the MultipartParser java class manage this upload
> process, but it seems that the file is readed fully although size of file
> is higher than parameter maxsize, żit is correct this behaviour?
>

Not always, if content length is available in the request object, the
MultipartParser reject the file without save it in memory nor disk. See
methods getParts(...) and parsePaths(...) methods [1]


>
> After debugging MultipartParser class, I see the process is:
> 1) if (oversized) , so if size of file is higher than parameter maxsize,
> then it is created object out = new NullOutputStream();
> 2) stream of file is readed and put into object out, and variable lenght
> is size of readed content.
> 3) if (oversized) then it is created object RejectedPart.
>
> I don't understand because read full file if in this case always it's
> created RejectedPart object. it's necesary length variable for RejectedPart
> object?.
>

The rejected part is a dummy representation so you can get information
about the rejected object. You can see in javadoc [2] that getImputStream()
method will throw an IOException.

I've rescue a snippet from an old project that used this:


//To handle the file upload limit we can detect if the part is instance of
//       org.apache.cocoon.servlet.multipart.RejectedPart

final Part part = RequestUtil.getPart(getRequest());
if(part instanceof RejectedPart) {
     throw new IllegalArgumentException("File size exceeds the maximum.");
}



>
> if at the begining of process you know content length of file and this
> number is higher of limit then it's better option not read file and create
> RejectedPart object with length = 0, isn't it?. Maybe, I don't know source
> of cocoon fully, and I am wrong.
>

I'm not sure 100% but it could be also related with your configuration
"autosave=true" that according to [3] it's responsible to store all the
uploaded files in the upload dir.


>
> Anybody can explain me.
>

I hope that avobe helps.

salu2.


> thanks
>

[1]
http://svn.apache.org/repos/asf/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartParser.java
[2]
http://cocoon.apache.org/2.2/core-modules/core/2.2/apidocs/org/apache/cocoon/servlet/multipart/RejectedPart.html
[3]
http://cocoon.apache.org/2.2/core-modules/core/2.2/apidocs/org/apache/cocoon/servlet/multipart/MultipartConfigurationHelper.html#autosaveUploads


>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.