Google app engine 要使用python将文件上载到google appengine中的目录吗

Google app engine 要使用python将文件上载到google appengine中的目录吗,google-app-engine,Google App Engine,我是谷歌appengine的新手。 我想上传一个文件到一个目录,而不是存储为blob main.py import cgi import webapp2 from google.appengine.api import users from google.appengine.ext.webapp.template \ import render from os import path class MainHandler(webapp2.RequestHandler): def

我是谷歌appengine的新手。 我想上传一个文件到一个目录,而不是存储为blob

main.py

import cgi 
import webapp2
from google.appengine.api import users
from google.appengine.ext.webapp.template \
    import render
from os import path

class MainHandler(webapp2.RequestHandler):
    def get(self):
        context={}
        tmpl = path.join(path.dirname(__file__), 'static/html/index.html')
        self.response.out.write(render(tmpl, context))

    def post(self):
       form_data = self.request.get('file')
       file_data = form_data
       f=open('static/html/'+form_data,'w')
       f.write(file_data)
       f.close



routes=[
        (r'/', MainHandler),
        ]   
app = webapp2.WSGIApplication(routes=routes,debug=True)
index.html

> <html>
>     <head><title>test</title></head>
>     <body>hello
>        <form id="addmovieform" action="/" method="post" ENCTYPE="multipart/form-data">
>            <input type="file" name="file" >
>            <input type="submit" name="submit">
>        </form>
>     </body>
>         </html>
>
>试验
>你好
>        
>            
>            
>        
>     
>         
错误

回溯(最近一次调用上次):文件 “/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py”, 第1536行,在调用中 rv=self.handle_异常(请求、响应、e)文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py”, 第1530行,在调用中 rv=self.router.dispatch(请求、响应)文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py”, 第1278行,默认为\u调度程序 返回route.handler_适配器(请求、响应)文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py”, 第1102行,在呼叫中 返回handler.dispatch()文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py”, 第572行,待命 返回self.handle_exception(e,self.app.debug)文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py”, 第570行,正在调度中 返回方法(*args,**kwargs)文件“/Users/saravase/test/main.py”,第33行,在post中 f=open('static/html/'+form_data,'w')文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google\u appengine/tools/dev\u appserver\u import\u hook.py”, 第589行,在init raise IOError('无效模式:%s'%mode)IOError:无效模式:w

请从“”引导我…

应用程序无法在任何运行时写入文件系统 环境。应用程序可以读取文件,但只能上载文件 使用应用程序代码。应用程序必须使用应用程序引擎数据存储, memcache或其他服务,用于在 请求。Python 2.7环境允许读取字节码, 书面的,修改过的

根据应用程序的需要,您需要返回到使用blobstore,或尝试使用。

From“”

应用程序无法在任何运行时写入文件系统 环境。应用程序可以读取文件,但只能上载文件 使用应用程序代码。应用程序必须使用应用程序引擎数据存储, memcache或其他服务,用于在 请求。Python 2.7环境允许读取字节码, 书面的,修改过的


根据应用程序的需要,您需要返回使用blobstore,或尝试使用。

为什么要这样做?在文件系统中存储数据绝对没有什么特别之处——实际上,您可以通过编写一个可以使用
StringIO
或blobstore执行的文件来执行任何操作。为什么要这样做?在文件系统中存储数据绝对没有什么特别之处—实际上,您可以通过编写一个文件来完成任何操作,该文件可以使用
StringIO
或blobstore来完成。