{"id":230607,"date":"2014-07-21T19:34:03","date_gmt":"2014-07-21T15:34:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=230607"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=230607","title":{"rendered":"<span class=\"post_title\">\u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0422\u043e\u0440\u043d\u0430\u0434\u043e: \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a \u0432 30 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430<\/span>"},"content":{"rendered":"<div class=\"content html_format\">     \t\u0412\u043f\u0435\u0440\u0432\u044b\u0435 \u0441\u043b\u044b\u0448\u0438\u0442\u0435 \u043e <a href=\"http:\/\/tornado.readthedocs.org\/\">tornado<\/a>? \u0421\u043b\u044b\u0448\u0430\u043b\u0438, \u043d\u043e \u0431\u043e\u044f\u043b\u0438\u0441\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0438? \u0421\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u043d\u0430 \u043d\u0435\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u0443\u0433\u043e\u0434\u0430 \u043d\u0430\u0437\u0430\u0434? \u0422\u043e\u0433\u0434\u0430 \u044f \u043f\u043e\u0441\u0432\u044f\u0449\u0430\u044e \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e \u0432\u0430\u043c \ud83d\ude42<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<h3>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430<\/h3>\n<p>  \u041f\u0438\u0441\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u043d\u0430 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u043f\u0438\u0442\u043e\u043d\u0435. \u0415\u0441\u043b\u0438 \u043e\u043d \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d, \u0441\u043e\u0432\u0435\u0442\u0443\u044e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <a href=\"https:\/\/github.com\/yyuu\/pyenv\/\">pyenv<\/a>. \u041a\u0440\u043e\u043c\u0435 <a href=\"http:\/\/tornado.readthedocs.org\/\">tornado<\/a> \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f <a href=\"http:\/\/motor.readthedocs.org\/\">motor<\/a> \u2014 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0434\u0440\u0430\u0439\u0432\u0435\u0440 \u043a mongodb:<\/p>\n<pre><code class=\"python\">pip3 install tornado motor <\/code><\/pre>\n<h3>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438<\/h3>\n<p>  <\/p>\n<pre><code class=\"python\">import bson import motor from tornado import web, gen, ioloop <\/code><\/pre>\n<h3>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a gridfs<\/h3>\n<p>  \u041a\u0430\u043a \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"http:\/\/docs.mongodb.org\/manual\/core\/gridfs\/\">gridfs<\/a>:<\/p>\n<pre><code class=\"python\">db = motor.MotorClient().habr_tornado gridfs = motor.MotorGridFS(db) <\/code><\/pre>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a <a href=\"http:\/\/docs.mongodb.org\/\">mongodb<\/a> \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0431\u0430\u0437\u0443 &#8216;habr_tornado&#8217;. \u0414\u0430\u043b\u0435\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a gridfs (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f fs).<\/p>\n<h3>Upload handler<\/h3>\n<p>  <\/p>\n<pre><code class=\"python\">class UploadHandler(web.RequestHandler):     @gen.coroutine     def get(self):         files = yield gridfs.find({}).sort(&quot;uploadDate&quot;, -1).to_list(20)         self.render('upload.html', files=files)      @gen.coroutine     def post(self):         file = self.request.files['file'][0]         gridin = yield gridfs.new_file(content_type=file.content_type)         yield gridin.write(file.body)         yield gridin.close()         self.redirect('') <\/code><\/pre>\n<p>  \u041c\u044b \u043e\u0442\u043d\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043e\u0442 <a href=\"http:\/\/tornado.readthedocs.org\/en\/latest\/web.html#request-handlers\">tornado.web.RequestHandler<\/a>. \u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044f \u043c\u0435\u0442\u043e\u0434\u044b get \u0438 post \u043f\u0438\u0448\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 http \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<p>  \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 <a href=\"http:\/\/tornado.readthedocs.org\/en\/stable\/gen.html#tornado.gen.coroutine\">tornado.gen.coroutine<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u043c\u0435\u0441\u0442\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b. \u0421\u0442\u043e\u0447\u043a\u0430 <code>files = yield gridfs ...<\/code> \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e \u043c\u0430\u043b\u043e \u0447\u0435\u043c \u043e\u0442\u043b\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e <code>files = gridfs<\/code>. \u041d\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u043e\u0433\u0440\u043e\u043c\u043d\u043e. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 <code>yield<\/code> \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0431\u0430\u0437\u0435 \u0438 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0435\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u043d\u0438\u044f. \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u043a\u0430 \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u00ab\u0434\u0443\u043c\u0430\u0442\u044c\u00bb, \u0441\u0430\u0439\u0442 \u0441\u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0434\u0440\u0443\u0433\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<p>  \u0418\u0442\u0430\u043a \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 get, \u043c\u044b \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0437 gridfs \u043c\u0435\u0442\u0430-\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u0430\u0445. \u0418 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0451 \u0432 \u0448\u0430\u0431\u043b\u043e\u043d.<\/p>\n<p>  \u0412 \u043c\u0435\u0442\u043e\u0434\u0435 <code>post<\/code> \u043c\u044b \u0434\u043e\u0441\u0442\u0430\u0451\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 (\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u043e\u0440\u043c\u044b \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0435) <a href=\"http:\/\/tornado.readthedocs.org\/en\/stable\/httputil.html#tornado.httputil.HTTPFile\">\u0444\u0430\u0439\u043b<\/a> \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f. \u0417\u0430\u0442\u0435\u043c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043e\u0442\u043a\u0440\u044b\u0430\u0435\u043c gridfs-\u0444\u0430\u0439\u043b, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0442\u0443\u0434\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442 \u043d\u0430 \u0442\u0443 \u0436\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u0444\u0430\u0439\u043b\u043e\u0432.<\/p>\n<h3>ShowImageHandler<\/h3>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0438\u0437 gridfs \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"python\">class ShowImageHandler(web.RequestHandler):     @gen.coroutine     def get(self, img_id):         try:             gridout = yield gridfs.get(bson.objectid.ObjectId(img_id))         except (bson.errors.InvalidId, motor.gridfs.NoFile):             raise web.HTTPError(404)         self.set_header('Content-Type', gridout.content_type)         self.set_header('Content-Length', gridout.length)         yield gridout.stream_to_handler(self) <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e GET \u0445\u0442\u0442\u043f \u0437\u0430\u043f\u0440\u043e\u0441. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0438\u0437 gridfs \u043f\u043e id. \u042d\u0442\u043e\u0442 id \u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d \u0438 \u0431\u044b\u043b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u043f\u0440\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 UploadHandler. \u0415\u0441\u043b\u0438 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f (\u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 id \u0438\u043b\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0444\u0430\u0439\u043b) \u2014 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c 404-\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443. \u0414\u0430\u043b\u0435\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043b \u043e\u0442\u0432\u0435\u0442 \u043a\u0430\u043a \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435. \u0418 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043e\u0442\u0434\u0430\u0451\u043c \u0442\u0435\u043b\u043e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438.<\/p>\n<h3>\u0420\u043e\u0443\u0442\u0438\u043d\u0433<\/h3>\n<p>  \u0414\u043b\u044f \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u043d\u0430\u0448\u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 (UploadHandler \u0438 ShowImageHandler) \u043a url, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <a href=\"http:\/\/tornado.readthedocs.org\/en\/stable\/web.html#tornado.web.RequestHandler.application\">tornado.web.Application<\/a>:<\/p>\n<pre><code class=\"python\">app = web.Application([     web.url(r'\/', UploadHandler),     web.url(r'\/imgs\/([\\w\\d]+)', ShowImageHandler, name='show_image'), ]) <\/code><\/pre>\n<p>  \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 url-\u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043e\u043a \u043d\u0430 \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438. \u0413\u0440\u0443\u043f\u043f\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043a\u0438 <code>([\\w\\d]+)<\/code> \u043a\u0430\u043a \u0440\u0430\u0437 \u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 <code>ShowImageHandler.get<\/code> \u043a\u0430\u043a <code>img_id<\/code>. \u0410 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>name='show_image'<\/code> \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0435 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0443\u0440\u043b.<\/p>\n<h3>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440<\/h3>\n<p>  <\/p>\n<pre><code class=\"python\">app.listen(8000) ioloop.IOLoop.instance().start() <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435: <a href=\"http:\/\/localhost:8000\/\">http:\/\/localhost:8000\/<\/a><\/p>\n<h3>\u0428\u0430\u0431\u043b\u043e\u043d<\/h3>\n<p>  <\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt; &lt;html&gt;     &lt;h1&gt;Upload an image&lt;\/h1&gt;     &lt;form action=&quot;&quot; method=&quot;post&quot; enctype=&quot;multipart\/form-data&quot;&gt;         &lt;input type=&quot;file&quot; name=&quot;file&quot; accept=&quot;image\/*&quot; onchange=&quot;javascript:this.form.submit()&quot;&gt;     &lt;\/form&gt;      &lt;h2&gt;Recent uploads&lt;\/h2&gt;     {% for file in files %}         {% set url = reverse_url('show_image', file['_id']) %}         &lt;a href=&quot;{{ url }}&quot;&gt;&lt;img src=&quot;{{ url }}&quot; style=&quot;max-width: 50px;&quot;&gt;&lt;\/a&gt;     {% end %} &lt;\/html&gt; <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0432\u0430\u043c \u0432\u0441\u0451 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u043d\u0430\u043a\u043e\u043c\u043e \u043f\u043e django \u0438\u043b\u0438 jinja. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435: <code>end<\/code> \u0432\u043c\u0435\u0441\u0442\u043e <code>endfor<\/code> \ud83d\ude42<\/p>\n<h3>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/h3>\n<p>  \u0418\u0442\u0430\u043a \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0431\u044b\u0441\u0442\u0440\u044b\u0439, \u043c\u0430\u0441\u0448\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u0439, \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043f\u043e \u0441\u0432\u043e\u0435\u0439 \u0441\u0443\u0442\u0438, \u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b\u0439 \u0432 \u043f\u0441\u0435\u0432\u0434\u043e-\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a. \u0410 \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u044b: \u0440\u043e\u0443\u0442\u0438\u043d\u0433, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u0432 <a href=\"http:\/\/tornado.readthedocs.org\/\">tornado<\/a>. \u0410 \u0442\u0430\u043a \u0436\u0435 \u0443\u043c\u0435\u0435\u0442\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 <a href=\"http:\/\/docs.mongodb.org\/\">mongodb<\/a> \u0438 <a href=\"http:\/\/docs.mongodb.org\/manual\/core\/gridfs\/\">gridfs<\/a> \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438.<\/p>\n<h3>\u041d\u043e &#8230;<\/h3>\n<p>  \u0412\u044b \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438 \u043e\u0434\u043d\u043e \u0443\u0437\u043a\u043e\u0435 \u043c\u0435\u0441\u0442\u043e: <code>file = self.request.files['file'][0]<\/code>. \u0414\u0430, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043c\u044b \u0433\u0440\u0443\u0437\u0438\u043c \u0432\u0435\u0441\u044c \u0444\u0430\u0439\u043b \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0431\u0430\u0437\u0443. \u0418 \u0432\u044b \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u043f\u043e\u0434\u0443\u043c\u044b\u0432\u0430\u0435\u0442\u0435 \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0447\u0435\u043c-\u0442\u043e \u0442\u0438\u043f\u0430 <a href=\"http:\/\/wiki.nginx.org\/HttpUploadModule\">NginxHttpUploadModule<\/a>. \u041e\u0434\u043d\u0430\u043a\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 tornado: <a href=\"http:\/\/tornado.readthedocs.org\/en\/stable\/web.html#tornado.web.stream_request_body\">tornado.web.stream_request_body<\/a>. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u044d\u0442\u043e \u043c\u044b \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0443\u0440\u043e\u043a\u043e\u0432.<\/p>\n<h3>C\u0441\u044b\u043b\u043a\u0438<\/h3>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/imbolc\/habr-modern-tornado\">\u043a\u043e\u0434 \u044d\u0442\u043e\u0433\u043e \u0443\u0440\u043e\u043a\u0430<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/yyuu\/pyenv\/\">pyenv<\/a><\/li>\n<li><a href=\"http:\/\/tornado.readthedocs.org\/\">tornado<\/a><\/li>\n<li><a href=\"http:\/\/motor.readthedocs.org\/\">motor<\/a><\/li>\n<li><a href=\"http:\/\/docs.mongodb.org\/\">mongodb<\/a><\/li>\n<\/ul>\n<h3>\u0412\u0430\u0448\u0435 \u043c\u043d\u0435\u043d\u0438\u0435<\/h3>\n<p>  \u041f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u043e\u0441\u044c \u043b\u0438? \u0421\u0442\u043e\u0438\u0442 \u043b\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c? \u0418\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f? \u041f\u043e\u0436\u0435\u043b\u0430\u043d\u0438\u044f?      \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/230607\/\"> http:\/\/habrahabr.ru\/post\/230607\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">     \t\u0412\u043f\u0435\u0440\u0432\u044b\u0435 \u0441\u043b\u044b\u0448\u0438\u0442\u0435 \u043e <a href=\"http:\/\/tornado.readthedocs.org\/\">tornado<\/a>? \u0421\u043b\u044b\u0448\u0430\u043b\u0438, \u043d\u043e \u0431\u043e\u044f\u043b\u0438\u0441\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0438? \u0421\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u043d\u0430 \u043d\u0435\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u0443\u0433\u043e\u0434\u0430 \u043d\u0430\u0437\u0430\u0434? \u0422\u043e\u0433\u0434\u0430 \u044f \u043f\u043e\u0441\u0432\u044f\u0449\u0430\u044e \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e \u0432\u0430\u043c \ud83d\ude42<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-230607","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/230607","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=230607"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/230607\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=230607"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=230607"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=230607"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}