[albatross-users] Questions

Dave Cole djc at object-craft.com.au
Sat Sep 21 23:07:05 EST 2002


> We are building an application that will process image files (JPGs,
> GIFs, etc.) uploaded by the user.
> 
> 1) How do we get to the Content-Type to figure out the content type of
>    the uploaded file

ctx.request.get_header('Content-Type')

> 2) How do we get to the file name that the user specified?

To handle file uploading you will need to make a slight change to the
Request class to detect when a field is of type file and return
something other then a plain value.

For example in cgiapp.Request.field_value() you would need to do
something like this:

    def field_value(self, name):
        field = self.__fields[name]
        if type(field) is type([]):
            value = []
            for elem in field:
                value.append(elem.value)
            return value
+       if hasattr(field, 'filename'):
+           return field
        return field.value

This would just return the raw request field which you handle as per
normal cgi file upload.

Retro-fitting file upload to apacheapp.Request would require something
similar.

> 3) How do we limit the memory used during a binary file upload and
>    provide a way to gracefully inform the user that they have exceeded
>    this size and must therefore upload a file with less number of bytes?

The standard Python cgi module does not read the entire file into
memory - it reads and writes 8k at a time.  The mod_python module
seems to read everything as text.

The Python cgi module has a maxlen variable which you can set to your
maximum file size.

At some stage we will have to implement file upload capability for
Albatross.

- Dave

-- 
http://www.object-craft.com.au




More information about the Albatross-users mailing list