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
> 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