Hi all!
I create "my page" using httprequest to upload file, but it cannot get file upload.
page load forever when run to line code :"fs = cgi.FieldStorage(fp=fp, environ=environ)"
Any one help me.
Thank very must!
And this is my code:
import glob
import itertools
import json
import operator
import os
from mako.template import Template
from openerp.modules import module
from openerp.addons.web.controllers.main import module_topological_sort
from openerp.addons.web import http
import cgi, os
import cgitb; cgitb.enable()
from httplib import HTTP
import urlparse
temp = """<html><body>
<form method="post" action="/sa/save">
<p>File: <input type="file" name="myfile"></p>
<p><input type="submit" value="Upload"></p>
</form>
</body></html>"""
class simplecontroller(http.Controller):
_cp_path = '/sa'
@http.httprequest
def index(self, req, **kwargs):
return temp
@http.httprequest
def save(self, req, **kwargs):
environ = req.httprequest.environ
fp=environ['wsgi.input']
fs = cgi.FieldStorage(fp=fp, environ=environ)# delay forever when run this line
f = fs.getfirst('myfile')
filepath =req.params.get('myfile')
fout = open(filepath,'w')
fout.write(f.file.read())
fout.close()
return "upload successfully"
up, help me !