Catching exceeded uploadLimit

3 views
Skip to first unread message

Anton Pirker

unread,
May 7, 2009, 1:59:00 AM5/7/09
to he...@googlegroups.com
Hi guys!

I have my uploadLimit in Helma set to 1024kb. And if try to upload an
image bigger than the I get an error. (this all works good)

But how can I catch this error? I have also error and notfound actions
set in my app.properties but the upload error ignores this and display
just the standard helma "File upload size exceeds limit of xx kb" message.

Is there a way to catch this kind of error?

Thanks,
Anton

--
DI(FH) Anton Pirker

-----------------------
ignaz software services
burggasse 123/53
a-1070 wien
tel: +43 699 1234 0 456
skype: antonpirker

http://anton-pirker.at
http://shnitzl.org

Hannes Wallnoefer

unread,
May 7, 2009, 4:39:02 AM5/7/09
to he...@googlegroups.com
Hi Anton,

you can set the uploadSoftfail property in apps.properties to true:

appname.uploadSoftfail = true

then you need to check the req.helma_upload_error property, which will
contain the error string if an upload failed. This feature was
contributed by Knallgrau if I remember correctly and may be
undocumented.

Hannes

2009/5/7 Anton Pirker <an...@ignaz.at>:

Anton Pirker

unread,
May 7, 2009, 5:11:55 AM5/7/09
to he...@googlegroups.com
Hi Hannes!

Thanks for the hint! It works as advertised!
I have added this property to:
http://dev.helma.org/docs/Properties+Files/apps.properties/

cheers,
Anton

Anton Pirker

unread,
May 15, 2009, 9:10:48 AM5/15/09
to Helma
I found strange behaviour with uploadSoftfail and helma_upload_error.

If i set uploadSoftfail in apps.properties to true and then add a file
that is bigger than the maximum i allow and i submit the form i get to
the action that is defined in the <form> tag, the
req.data.helma_upload_error contains the right error message but the
rest of req.data is empty. (And this is quite bad because i need the
entered stuff from the form to fill all the field that where ok with
the data entered before)

I had a look where the helma_upload_error is set. Its in helma/src/
helma/servlet/AbstractServletClient.java but i really don't know the
code so i cannot say what to change so the other req.data information
is not lost.

Could anyone with deeper knowledge of the helma code have a look?

Thanks,
Anton

Anton Pirker

unread,
May 20, 2009, 4:19:25 AM5/20/09
to he...@googlegroups.com
Hi again!

Has really no one used this feature?

I have attached a simple app that demonstrates how the rest of req.data
is cleared out when a helma_upload_error occurs.
How can i catch the helma_upload_error and still have all the data from
the other input fields in req.data?

Maybe someone of the Knallgrau folks can bring some light into this issue?
Please, this is a rather urgent issue for me.


Thanks in advance,
Anton
uploaderror-sample-app.zip

Andreas Bolka

unread,
May 21, 2009, 8:37:47 PM5/21/09
to he...@googlegroups.com
On Wed May 20 10:19:25 +0200 2009, Anton Pirker wrote:
> I have attached a simple app that demonstrates how the rest of
> req.data is cleared out when a helma_upload_error occurs.

> How can i catch the helma_upload_error and still have all the data
> from the other input fields in req.data?

Well, this way you simply can't, in general. But that's not due to Helma
but rather because of how those upload limits work.

In simplified terms: all your form data has to be sent from the browser
to the server somehow. In your situation, the form data consists of
multiple fields and one big file. The browser packs this all together
into a (big) request, which it sends to the server. Now the server
rejects this request at one point, as it exceeds the upload limit. And
as the server has not received the complete request, it is also not able
to reconstruct the data sent by the browser.

I can't think of a workaround that would not be ugly, but I'll be happy
if someone enlightens me. Here's the easiest thing that comes to my
mind: use a client-side script that runs just before the form is
submitted. Then join all non-file fields together into an
`x-www-form-urlencoded` string and append this to the form's action.

E.g. for a form like

<form method="post" action="/foo">
<input name="a" value="b">
<input name="c" value="d">
</form>

The script should append "?a=b&c=d" to the action before submitting the
form.

For simple forms you can do this by hand, but it gets rather messy with
more complex forms [1], so I'd suggest using jQuery's `serialize` [2]
instead.

[1] http://malsup.com/jquery/form/comp/
[2] http://docs.jquery.com/Ajax/serialize

Why does this work? It basically mimics the way forms are sent when
using `method="get"`, encoding the form data into the URL. And as the
URL is prominently sent in the request line (the very first line sent in
an HTTP request), the server will always have received this information,
even if the server has to reject/truncate the request's message body
later on.

--
Regards,
Andreas

Reply all
Reply to author
Forward
0 new messages