在Google AppEngine中检索.txt文件内容 [英] Retrieving .txt file contents in Google AppEngine
本文介绍了在Google AppEngine中检索.txt文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用以下方式上传文本文件:
< input type =filename =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)
我的输出是:
内容类型:text / plain MIME版本:1.0内容-Length:312 Content-MD5:MDIzYzM5YmNmOWRmMzY5Zjk2MTYzZTUzNjYwMTg5YjM = content-type:text / plain content-disposition:form-data; NAME = 文件; filename =blah.txtX-AppEngine-Upload-Creation:2013-04-24 07:57:23.729774
有什么办法可以检索文件内容而不是上面的标题。
//form.gae-init.appspot.com/rel =nofollow>现场示例): import webapp2
$ b $ class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.headers ['Content-Type'] =text / html
self.response.write('''
< form action =/ uploadenctype =multipart / form-datamethod =post>
< input类型=文件名称=文件>
< 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',UploadHand ler)
],debug = True)
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)
这篇关于在Google AppEngine中检索.txt文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文