Kenneth Brown wrote:
> This is driving me swiftly insane.
> 
> I'm working on a page that uploads images. I've tried a few ways of
> pulling the file data out of the request and writing it to
> disk, but it
> always ends up corrupted and/or truncated (I'm not sure which)
> 
> The form sets enctype="multipart/form-data". The input in the form is
> named "file". 
> 
> Here's a condensed version of the code I'm currently trying:
> 
> uploadedFile = self.request().field("file", None).file
> uploadedFile.seek(0) fileContents = uploadedFile.read()
> file("/tmp/file.jpg", 'wb').write(fileContents)
> 
> I've tried a while loop that read line by line, pulling the string out
> of the FieldStorage object, nothing seems to work.
> 
> I'm uploading from Opera 7.23, though I've tried Mozilla as well. I'm
> running Webware 8.1 with the apache2 adapter.
> 
> Any ideas?
> 
> -Ken Brown

I can't get this to fail on Windows, but I do see some suspicious-looking
code in WebKit/Adapters/mod_webkit2/mod_webkit.c.

This loop at line 391:

            do {
                aprlen=len;
                rv = apr_send(aprsock, data, &aprlen);
                len = len-aprlen;
            } while (len >0 && rv==APR_SUCCESS);

seems broken because if the apr_send is unable to send the whole length of
data at once, it will try to resend from the beginning of the data instead
of advancing the pointer by the amount sent.  This would result in a small
block of repeated data which is exactly what you're seeing.  Try this and
see if it helps:

            do {
                aprlen=len;
                rv = apr_send(aprsock, data, &aprlen);
                len = len-aprlen;
                data += aprlen;
            } while (len >0 && rv==APR_SUCCESS);

- Geoff


-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to