{"id":1806,"date":"2009-10-21T01:36:50","date_gmt":"2009-10-20T16:36:50","guid":{"rendered":"http:\/\/fukata.org\/?p=1806"},"modified":"2017-08-11T22:59:08","modified_gmt":"2017-08-11T22:59:08","slug":"python-mod_python-download","status":"publish","type":"post","link":"https:\/\/blog.fukata.org\/archives\/1806\/","title":{"rendered":"[Python]mod_python\u4f7f\u7528\u6642\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u51e6\u7406"},"content":{"rendered":"

\u73fe\u5728\u3001python\u3092\u52c9\u5f37\u4e2d\u3067\u3061\u3087\u3063\u3068\u3057\u305fWEB\u30a2\u30d7\u30ea\u3092\u4f5c\u3063\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u51e6\u7406\u3092\u66f8\u304b\u306a\u3044\u3068\u3044\u3051\u306a\u304f\u306a\u3063\u305f\u306e\u3067\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u3088\u304b\u3063\u305f\u3089\u3069\u3046\u305e\u3002<\/p>\n

\r\n# -*- coding: utf-8 -*-\r\n\r\nimport sys\r\nimport os\r\n\r\ndef download(req,filepath):\r\n\r\n    req.content_type = 'application\/octet-stream'\r\n    req.headers_out['Content-Type'] = 'application\/octet-stream'\r\n    req.headers_out['Content-Disposition'] = \"attachment; filename=\\\"\" + os.path.basename(filepath)\r\n    req.headers_out['Content-Length'] = str(os.path.getsize(filepath))\r\n    req.headers_out['Expires'] = '0'\r\n    req.headers_out['Cache-Control'] = 'must-revalidate, post-check=0,pre-check=0'\r\n    req.headers_out['Pragma'] = 'private'\r\n\r\n    if sys.platform == \"win32\":\r\n        import msvcrt\r\n        msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)\r\n\r\n    return req.sendfile(filepath)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u73fe\u5728\u3001python\u3092\u52c9\u5f37\u4e2d\u3067\u3061\u3087\u3063\u3068\u3057\u305fWEB\u30a2\u30d7\u30ea\u3092\u4f5c\u3063\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u51e6\u7406\u3092\u66f8\u304b\u306a\u3044\u3068\u3044\u3051\u306a\u304f\u306a\u3063\u305f\u306e\u3067\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u3088\u304b\u3063\u305f\u3089\u3069\u3046\u305e\u3002 # -*- coding: … \u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":2,"featured_media":9223372036854775807,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1980],"tags":[398,1086,399],"_links":{"self":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/1806"}],"collection":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/comments?post=1806"}],"version-history":[{"count":0,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/1806\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media\/9223372036854775807"}],"wp:attachment":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media?parent=1806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/categories?post=1806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/tags?post=1806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}