I'm creating an web app in Pylons, and am working on an image upload action. This is currently running using egg:paste#http on my windows machine, in the basic development configuration described in the pylons documentation quickstart.
When I POST an image to my application, then move the image to the web root directory, then pull the uploaded image up in the browser, the image appears distorted. This is what I got when i uploaded a GIF of the Yahoo! logo, but most files don't show up in the browser at all, presumably because of corruption:
distorted yahoo logo http://www.freeimagehosting.net/uploads/d2c92aef00.png
This is the basic code I'm working with (straight out of the pylons documentation):
os_path = os.path.join(config.images_dir, request.POST['image'].filename)
save_file = open(os_path, 'w')
shutil.copyfileobj(request.POST['image'].file, save_file)
request.POST['image'].file.close()
save_file.close()
request.POST['image'] is a cgi.FieldStorage object. I thought this may be an issue with Windows line endings somehow, but I'm not sure how to check that or correct for it. What is causing my uploaded images to be distorted / corrupt?