我是谷歌应用引擎的新手。我想将文件上传到目录而不是存储为 blob。
主文件
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)
索引.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>
错误
Traceback(最近一次通话最后):文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py”,第 1536 行,调用 rv = self .handle_exception(request, response, e) 文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py”,第 1530 行,通话中 rv = self.router.dispatch(request, response) 文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py”,第 1278 行,在default_dispatcher return route.handler_adapter(request, response) 文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py”,第 1102 行,通话中 return handler.dispatch() File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py",第 572 行,在 dispatch return 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 行,在帖子 f=open('static/html/'+form_data,'w') 文件“/Applications/GoogleAppEngineLauncher. app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py”,第 589 行,在初始化 raise IOError('invalid mode: %s' % mode) IOError: invalid mode: w
请指导我...