Problem saving uploaded files in Python3

Chris Rebert clp2 at rebertia.com
Sat Oct 2 08:18:00 CEST 2010


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?

If you're on Windows, you'll need to open the file in binary mode:
s = open('/home/hidura/test.png', 'wb')

If you're not on Windows, then something else is the problem.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list