1

I am new to python and I am assigned the task of making an image uploade script from a webform in python. We are using Pylons.
I have a form submitting to a page and am trying to run the follow but I am getting this error

AttributeError: read

My code is this:

im = Image.open(request.POST['image'])  
im = im.convert("RGB")  
im = im.resize((70,70), Image.ANTIALIAS)  
im.save("/avatars/q5.png")

Any help is greatly, greatly appreciated!

mahle
  • 233
  • 1
  • 2
  • 13
  • How are you uploading the Image? Using HTML Form for using Python itself? If using python are you sending the proper `Content-Type:application/x-www-form-urlencoded` header? – Senthil Kumaran Mar 02 '11 at 06:26

1 Answers1

1

I think you want to do this:

im = Image.open(StringIO(request.POST['image']))

since the Image.open function takes a file-like object not a buffer. The StringIO packages turns a buffer into a file-like object.

jterrace
  • 64,866
  • 22
  • 157
  • 202
  • I did that. Now I am getting IOError: cannot identify image file. Does that mean the file is coming throught the form properly? – mahle Mar 02 '11 at 02:41
  • Yeah, that sounds like it's not being uploaded properly. Check to make sure length(request.POST['image']) is the number of bytes that the file is supposed to be. – jterrace Mar 02 '11 at 03:03