Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Cannot get file upload by "environ" in my page using httprequest

By
Nguyễn Xuân Huy
on 6/4/14, 11:54 PM 1,122 views

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 !

Nguyễn Xuân Huy
on 6/10/14, 6:34 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 6/4/14, 11:54 PM
Seen: 1122 times
Last updated: 3/16/15, 8:10 AM