[英]Retrieving .txt file contents in Google AppEngine
I'm trying to Upload a text file using : 我正在尝试上传文本文件:
<input type="file" name="file">
and this file is retrieved using: 并使用以下方法检索此文件:
class UploadHandler(webapp2.RequestHandler):
def post(self):
file=self.request.POST['file']
self.response.headers['Content-Type'] = "text/plain"
self.response.write(file.value)
my output is: 我的输出是:
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
Is there any way i could retrive the file content instead of above headers. 有什么方法可以检索文件内容而不是上面的标题。 ??
??
The following seems to work, so there must be something else that is happening ( live example ): 以下似乎有效,所以必须有其他事情发生( 实例 ):
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.