[Yanel-dev] Refactor max file upload size

Michael Wechner michael.wechner at wyona.com
Thu Dec 12 21:30:33 CET 2013


Hi

I have finally refactored HttpRequest.java  and YanelFilter, such that
one can define a max file size, whereas see

https://github.com/wyona/yanel/issues/38#issuecomment-30457750

This is not perfect though, because

- it would be better to have this configurable per resource
- when the file is too big, than an exception is generated, because the
request parsing fails and all query parameters are being dropped
(related to this see for example
http://stackoverflow.com/questions/13881272/servletfileuploadparserequestrequest-returns-an-empty-list)

I will try to improve it further, but at least it is now configurable

Thanks

Michael

Am 11.02.09 11:25, schrieb Michael Wechner:
> Hi
>
> It seems that within
>
> src/webapp/src/java/org/wyona/yanel/servlet/communication/HttpRequest.java
>
>
> the file upload size is hard-coded and I think we should refactor it:
>
> Index: src/resources/file/resource.xml
> ===================================================================
> --- src/resources/file/resource.xml     (Revision 41484)
> +++ src/resources/file/resource.xml     (Arbeitskopie)
> @@ -18,5 +18,6 @@
>   <!-- For example (IMPORTANT: Do not forget the leading slash!)
>     <yanel:property name="src" value="/index.html"/>
>   -->
> +  <property name="max-file-upload-size"/> <!-- kilo bytes -->
> </rtd>
> </resource>
>
>
> Index:
> src/resources/file/src/java/org/wyona/yanel/impl/resources/node/NodeResource.java
> ===================================================================
> ---
> src/resources/file/src/java/org/wyona/yanel/impl/resources/node/NodeResource.java  
> (Revision 41484)
> +++
> src/resources/file/src/java/org/wyona/yanel/impl/resources/node/NodeResource.java  
> (Arbeitskopie)@@ -313,6 +313,11 @@
>
>             if (request instanceof HttpRequest) {
>                 HttpRequest yanelRequest = (HttpRequest)request;
> +                String maxFileSize =
> getResourceConfigProperty("max-file-upload-size");
> +                if (maxFileSize != null) {
> +                    // TODO: Implement this method
> +                    //yanelRequest.setMaxFileSize(maxFileSize);
> +                }
>                 if (yanelRequest.isMultipartRequest()) {
>                     Enumeration parameters = yanelRequest.getFileNames();
>                     if (parameters.hasMoreElements()) {
>
>
> Index:
> src/webapp/src/java/org/wyona/yanel/servlet/communication/HttpRequest.java
> ===================================================================
> ---
> src/webapp/src/java/org/wyona/yanel/servlet/communication/HttpRequest.java 
> (Revision 41484)
> +++
> src/webapp/src/java/org/wyona/yanel/servlet/communication/HttpRequest.java 
> (Arbeitskopie)
> @@ -60,6 +60,7 @@
>                 DiskFileItemFactory factory = new DiskFileItemFactory();
>
>                 // Set factory constraints
> +                // TODO: Do not hardcode this size limitation
>                 factory.setSizeThreshold(64000);
>                 factory.setRepository(new
> File(System.getProperty("java.io.tmpdir")));
>                 //Create a new file upload handler
>
>
> WDYT?
>
> Cheers
>
> Michi



More information about the Yanel-development mailing list