Upload image from webform in Python
I am new to python and I am assigned the task of making an ima开发者_运维百科ge 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 errorAttributeError: 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!
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.
精彩评论