I answered my own question. I used PIL (Python Image Library) and
passed in a StringIO buffer to create an image object.
import Image
import StringIO
i = web.input()
im = Image.open(StringIO.StringIO(i.imgfile))
On Aug 16, 1:21 pm, JohnK <[EMAIL PROTECTED]> wrote:
> Hi - I'm looking for some pointers on the best way to save an uploaded
> image. I'm able to get the file via the upload in the POST handler and
> then write it out to disk, but when I open the file, it's clearly not
> formatted as a jpeg. Any advice? Is there some formatting trick I
> should be using?
>
> CODE.PY
>
> import web
>
> render = web.template.render('templates/')
>
> urls = ('/images/upload','upload_image')
>
> class upload_image:
> def GET(self):
> print render.upload_image()
> def POST(self):
> i = web.input()
> file=open('1.jpg', 'w')
> file.write(i.imgfile)
> file.close()
>
> web.webapi.internalerror = web.debugerror
>
> if __name__ == "__main__": web.run(urls, globals(), web.reloader)
>
> UPLOAD_IMAGE.HTML
>
> $def with ()
>
> <html>
> <form method="post" action="./upload" enctype="multipart/form-data">
> <input type="file" name="imgfile" size="75">
> <input type="submit" value="submit"/>
> </form>
> </ html>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---