[Tutor] Question about cgi module

Andreas Kostyrka andreas at kostyrka.org
Fri Apr 20 22:38:59 CEST 2007


* Mike Hansen <Mike.Hansen at atmel.com> [070420 22:32]:
> Part of the web app that I'm writing will allow users to upload small
> images to be stored in a database. Is there a way to limit how big of a
> file that the user can upload? Is there some cgi setting that would
> prevent a user from upload a huge file, or stop at a certain size and
> error?

Not really. Perhaps.

You need envision the situtation:

http wise, the client assembles its request, and starts to send it to
the server. the http server is allowed to drop a http connection
anytime, and because file uploads are POSTs, the client should not
resent it without manual intervention by the user.

cgi wise, you need to check how your http server handles it.

Furthermore, you've got the little problem, that the standard cgi
module probably won't support that directly.

After having taken a view on the technical side, let's look at it from
the users perspective:

a) the error comes after the file was uploaded. Not much you can do
against that (Well, if you manage to interpret a Content-Length
header, you might abort the upload earlier, in theory).

b) aborting the request gives no sensible feedback to the user.

The typical solution for that is to use AJAX:

1.) get an unique id for the upload.
2.) post the file to an url containing the unique id.
3.) check the status of the upload via an AJAX method to give sensible
status messages, including errors.

(you need the unique id so that the AJAX calls can retrieve the status)

Andreas


More information about the Tutor mailing list