[mod_python] BMP upload problems

David Fraser davidf at sjsoft.com
Fri Apr 16 08:40:10 EST 2004


Aaron Prillaman wrote:

> In uploading a bmp file with the following setup, something is 
> corrupting the data.
>  
> I have a very simple python script:
> tst.py..........
>  
> from mod_python import util
> datadir = '/Documents and Settings/owner/desktop/www/data/'
>  
> def upload(req,sfl):
>     sdata = req.form['sfl'].file.read()
>     ofl = open(datadir+"tst.bmp","w")
>     ofl.write(sdata)
>     return "ok"
>  
> and a simple form:
> http://mollysgrave.no-ip.com:82/tst.html
> tst.html............
>  
> <html>
> <form action="/cgi-bin/tst.py/upload" method="post" 
> enctype="multipart/form-data"><br>
> file: <input type="file" name="sfl">
> <input type="submit">
> </form>
> </html>
> I upload http://mollysgrave.no-ip.com:82/brown1.bmp
> and http://mollysgrave.no-ip.com:82/tst.bmp is the result.
> I'm not really sure what the inconsistency is.  Just wondering if 
> anyone has ideas.
>  
> Thanks,
> Aaron Prillaman

tst.bmp is the same as unix2dos of brown1.bmp i.e. all the LFs are being 
replaced by CR LF
So the likely reason is when writing the file you need to open it in 
binary form ("wb" instead of "w")

David


More information about the Mod_python mailing list