views:

27

answers:

1

I'm having a problem with file uploading. I'm using FastCGI on Apache2 (unix) to run a WSGI-compliant application. File uploads, in the form of images, are begin saved in a MySQL database. However, larger images are being truncated at 65535 bytes. As far as I can tell, nothing should be limiting the size of the files and I'm not sure which one of the pieces in my solution would be causing the problem.

Is it FastCGI; can it limit file upload sizes?

Is it Python? The cgi.FieldStorage object gives me a file handle to the uploaded file which I then read: file.read(). Does this limit file sizes in any way?

Is it MySQL? The type of the column for saving the image data is a longblob. I figured this could store a couple of GB worth of data. So a few MB shouldn't be a problem, right?

Is it the flups WSGIServer? I can't find any information regarding this.

My file system can definitely handle huge files, so that's not a problem. Any ideas?

UPDATE:

It is MySQL. I got python to output the number of bytes uploaded and it's greater than 65535. So I looked into max_allowed_packet for mysqld and set it to 128M. Overkill, but wanting to be sure for the moment.

My only problem now is getting python's MySQLdb to allow the transfer of more than 65535 bytes. Does anyone know how to do this? Might post as a separate question.

+2  A: 

If the web server/gateway layer were truncating incoming form submissions I'd expect an error from FieldStorage, since the truncation would not just interrupt the file upload but also the whole multipart/form-data structure. Even if cgi.py tolerated this, it would be very unlikely to have truncated the multipart at just the right place to leave exactly 2**16-1 bytes of file upload.

So I would suspect MySQL. LONGBLOB should be fine up to 2**32-1, but 65535 would be the maximum length of a normal BLOB. Are you sure the types are what you think? Check with SHOW CREATE TABLE x. Which database layer are you using to get the data in?

bobince
+1. I believe it is MySQL as well. If not the database itself (wrong column type), then maybe some setting in the driver.
Thilo
I am using python's MySQLdb module and calling stored procedures through that. The column type was originally a `BLOB` but after looking up size restrictions I upgraded it to a `LONGBLOB`.
Duracell
Correct, it was MySQL. It was actually limitations on the `max_allowed_packet` for both client and server.
Duracell