UPDATE
By insisting I'll post the code to load more than one file at a time:
In the http.py file must comment a line and add another, in the line 608:
http.py
class HttpRequest(WebRequest):
""" Handler for the ``http`` request type.
matched routing parameters, query string parameters, form_ parameters
and files are passed to the handler method as keyword arguments.
In case of name conflict, routing parameters have priority.
The handler method's result can be:
* a falsy value, in which case the HTTP response will be an
`HTTP 204`_ (No Content)
* a werkzeug Response object, which is returned as-is
* a ``str`` or ``unicode``, will be wrapped in a Response object and
interpreted as HTML
.. _form: http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2
.. _HTTP 204: http://tools.ietf.org/html/rfc7231#section-6.3.5
"""
_request_type = "http"
def __init__(self, *args):
super(HttpRequest, self).__init__(*args)
params = self.httprequest.args.to_dict()
params.update(self.httprequest.form.to_dict())
#params.update(self.httprequest.files.to_dict())
params.update(self.httprequest.files) # Modified line
params.pop('session_id', None)
self.params = params
My controller:
from openerp import http
import simplejson
import time
import os
import StringIO
class Binary_Multi(http.Controller):
@http.route('/web/binary/multi_picture_upload', type="http", auth="public")
def multi_picture_upload(self, req, callback, ufile):
out = """<script language="javascript src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" type="text/javascript">
var win = window.top.window;
win.jQuery(win).trigger(%s, %s);
</script>"""
args = []
for nfile in ufile:
data = nfile.read()
current_dat_time = time.strftime("%d-%m-%Y-%H_%M_%S")
file_name = current_dat_time + "_" + nfile.filename
addons_path = http.addons_manifest['web']['addons_path'] +\
"/web/static/src/img/image_multi/"
if not os.path.isdir(addons_path):
os.mkdir(addons_path)
addons_path += file_name
buff = StringIO.StringIO()
buff.write(data)
buff.seek(0)
file_name = "/web/static/src/img/image_multi/" + file_name
file = open(addons_path, 'wb')
file.write(buff.read())
file.close()
args.append([len(data), file_name, nfile.content_type,
nfile.filename, time.strftime("%m/%d/%Y %H:%M:%S")])
return out % (simplejson.dumps(callback), simplejson.dumps(args))
Now you can scroll through the list with for loop
but this would cause us a problem, if we upload attachments in fields.Binary.
I modify the core again to use both, my multiple images fields and traditional fields.Binary attachments.
class HttpRequest(WebRequest):
""" Handler for the ``http`` request type.
matched routing parameters, query string parameters, form_ parameters
and files are passed to the handler method as keyword arguments.
In case of name conflict, routing parameters have priority.
The handler method's result can be:
* a falsy value, in which case the HTTP response will be an
`HTTP 204`_ (No Content)
* a werkzeug Response object, which is returned as-is
* a ``str`` or ``unicode``, will be wrapped in a Response object and
interpreted as HTML
.. _form: http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2
.. _HTTP 204: http://tools.ietf.org/html/rfc7231#section-6.3.5
"""
_request_type = "http"
def __init__(self, *args):
super(HttpRequest, self).__init__(*args)
params = self.httprequest.args.to_dict()
params.update(self.httprequest.form.to_dict())
#params.update(self.httprequest.files.to_dict())
str_args = str(args)
# If the request is from my controller,( in tis case, multi_picture_upload)then use modified line
if str_args.find("multi_picture_upload") >=0: #
params.update(self.httprequest.files)
# Else, just use the original line
else:
params.update(self.httprequest.files.to_dict())
params.pop('session_id', None)
self.params = params
sorry that my code is so ugly/akward, and my English so bad.