TornadoWeb + Google App Engine Загрузка картинок

24 views
Skip to first unread message

ardei

unread,
Dec 1, 2011, 5:11:17 AM12/1/11
to google-ap...@googlegroups.com
Может кто сталкивался с проблемой загрузки картинок в базу  GAE из TornadoWeb.
Подскажите, что я делаю не так.



import tornado.web
import tornado.wsgi
import tornado.httpserver
import tornado.ioloop
import os.path
import views


from google.appengine.api import images
from google.appengine.ext import db


class Picture(db.Model):
    title = db.StringProperty()
    data = db.BlobProperty()



class ImageLoadHandler(tornado.web.RequestHandler):
    def get(self):
        self.write('<html><body>'
                   '<form method="POST" enctype="multipart/form-data" action="/printfile">'
                   '<input type="text" name="title"  />'
                   '<input type=file name=upload><input type=submit name=press value="OK">'
                   '</form></body></html>')

    def post(self):
        title = self.get_argument('title')
        img_data = self.request.POST.get('upload').file.read()
        img = images.Image(img_data)
        img.resize(60, 60)
        Picture(title=title,
            data=img).put()

settings = {
    "site_title": u"test",
    "template_path": os.path.join(os.path.dirname(__file__), "templates"),
    "static_path": os.path.join(os.path.dirname(__file__), "static"),
    
}

application = tornado.wsgi.WSGIApplication([    
     (r"/img",ImageLoadHandler),
], **settings)


def main():
    wsgiref.handlers.CGIHandler().run(application)


if __name__ == "__main__":
    main()
myImage.txt
Reply all
Reply to author
Forward
0 new messages