我正在尝试使用以下命令上传文本文件:
<input type="file" name="file">
并且使用以下方式检索该文件:
class UploadHandler(webapp2.RequestHandler):
def post(self):
file=self.request.POST['file']
self.response.headers['Content-Type'] = "text/plain"
self.response.write(file.value)
我的输出是:
Content-Type: text/plain MIME-Version: 1.0 Content-Length: 312 Content-MD5: MDIzYzM5YmNmOWRmMzY5Zjk2MTYzZTUzNjYwMTg5YjM= content-type: text/plain content-disposition: form-data; name="file"; filename="blah.txt" X-AppEngine-Upload-Creation: 2013-04-24 07:57:23.729774
有什么方法可以检索文件内容而不是上面的标题。 ??
以下似乎有效,因此肯定还发生了其他事情(活生生的例子 http://form.gae-init.appspot.com/):
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = "text/html"
self.response.write('''
<form action="/upload" enctype="multipart/form-data" method="post">
<input type="file" name="file">
<input type="submit">
</form>
''')
class UploadHandler(webapp2.RequestHandler):
def post(self):
file = self.request.POST['file']
self.response.headers['Content-Type'] = "text/plain"
self.response.write(file.value)
app = webapp2.WSGIApplication([
('/', MainHandler),
('/upload', UploadHandler)
], debug=True)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)