[Yanel-dev] Refactor max file upload size
Michael Wechner
michael.wechner at wyona.com
Sun Dec 15 13:32:58 CET 2013
Hi
I thought some more about the problem with the "lost" query parameters
and also sent an email to
the Apache Commons mailing list to discuss possible solutions
http://mail-archives.apache.org/mod_mbox/commons-user/201312.mbox/browser
I think it's important to solve this problem somehow, but I am not sure
whether this will take another 5 years,
hence I thought about the following workaround:
- Set max-file-size to -1 inside the YanelFilter configuration, such
that the size is not limited by Yanel itself
- Handle the "max-file-size" inside the resource, by uploading the image
to a temporary folder, then
check the size there and when to big, delete the temporary file and
otherwise copy it to the actual location.
It's not a hack which I will be proud of, but at least it does the trick.
Thanks
Michael
Am 12.12.13 21:30, schrieb Michael Wechner:
> 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