Problem saving uploaded files in Python3

Diez B. Roggisch deets at web.de
Sat Oct 2 05:34:28 EDT 2010


Chris Rebert <clp2 at rebertia.com> writes:

> On Fri, Oct 1, 2010 at 11:13 PM,  <hidura at gmail.com> wrote:
>> Hello, i control the problem of the data what is uploaded by the POST
>> method, in the web if the file is a text theres no problem
>> but the trouble comes when it's an enconded file as a Picture or other what
>> the when the system insert the data into the file
>> well it doesn 't encoded in the write way i will put all the code, from the
>> area whats take the environ['wsgi.input'] to the area
>> thats save the file:
>>
>> tmpData = str(rawData)[1:].strip("' '")#Here the data from the
>> environ['wsgi.input'], first i convert the byte into a string delete the
>> first field that represent the b and after i strip the single quotes
>> dat = tmpData.split('\\r')#Then i split all the data in the '\\r'
>> s = open('/home/hidura/test.png', 'w')#I open the test.png file.
> <snip>
>> Where is the mistake?

In believing that wsgi.input is a simple file that contains your
upload. It isn't. It is multipart/form-data encoded, to cope with
potentially many files being uploaded in one go, plus assorted other
form fields.

In another post, you have already been shown how to do this. What where
the results? How does your full script look like? How does the form look
like you upload with?

Diez



More information about the Python-list mailing list