Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profit organisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

OpenERP multiple file upload

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
widgetuploadmultipleimagescontrollers
10 Antwoorden
22909 Weergaven
Avatar
Vicious

I'm programming a module in OpenERP to upload multiple images from a folder in one go, using HTML5 input multiple without uploading pictures one at a time and not store them in the database, with the loss of performance that implies, I save them as files, I have a form with a Widget that makes a POST request to a controller, the problem is that it print only the last FileStorage object, when I send more than one, to upload multiple files at a time , however I can not find how to modify it because I do not even like the web client decides to send an object of type FileStorage or other object!

My Widget

<t t-name="HiddenInputFileMulti">
        <div t-attf-class="oe_hidden_input_file #{fileupload_class or ''}" t-att-style="fileupload_style">
            <form class="oe_form_binary_form" t-att-target="fileupload_id" method="POST" enctype="multipart/form-data" action="/web/binary/multi_picture_upload">
                <t t-raw="__content__"/>
                <input type="file" id="files" class="oe_form_binary_file" name="ufile" accept="image/*" multiple=""/>
            </form>
        </div>
    </t>

My controller:

from openerp.addons.web import http as openerpweb
from openerp.addons.web.controllers.main import Binary

@openerpweb.httprequest
    def multi_picture_upload(self, req, ufile):

         print ufile #this print the last FileStorage object, in a dict like :FileStorage: u'tula.gif' ('image/gif')

EDIT:

I say forget that when I print the contents of ufile, It returns a dictionary with a single pair

<FileStorage: u'tula.gif' ('image/gif')>

this is the last picture I sent, and analyzing the request indeed, the web client sends all pictures, but the controller only receives the last, it seems like they just dismiss all previous images ....

3
Avatar
Annuleer
Avatar
Vicious
Auteur Beste antwoord

 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. 

1
Avatar
Annuleer
Vicious
Auteur

Forgot to say that when I print the contents of ufile, I returns a dictionary with a single pair FileStorage: u'tula.gif' ('image/gif') , this is the last picture I sent, and analyzing the request indeed, the web client sends all pictures, but the controller only receives the last, it seems like they just dismiss all previous images ....

Marcin Kieszek

Have you found a solution? I'm also interested in that case.

OdooBot
which case?
I have several post's
El 23/09/14 04:32, Bajkar escribió:
<blockquote cite="mid:1411461174.535656929016113.921812722042857-openerp-55718-forum.post@accounts.odoo.com" type="cite">

Have you found a solution? I'm also interested in that case.

--
Bajkar
Sent by OpenERP S.A. using Odoo about Forum Post False
Vicious
Auteur

Excuse me, answered from the email, I found a way to make it work, but modifying the core code

David Myers

@Vicious : I like what you are attempting to do here. However I think another potential idea for the process is as follows: link out to an ftp system, and use that to import the files. Obviously you'll need to enable the storage of files on disk rather than in the database. The improvement that I would like to see is to load in multiple image files into a galery in one hit. If I want to enable a gallery with a lot of images I have to spend a lot of time selecting them... which really agravates me, as my local pc is rather old!

Vicious
Auteur

@David Myers I already have it running a gallery, using a multiple charger taking the "multiple" property in html, what you say is completely valid, however my clients are very basic users, for each case, taking pictures with they digital camera, then create a folder on the PC, move all the photos to that folder, and the camera stays empty for the next occasion, then the in the Odoo, to get you out the window to select files for all the selected (Ctrl + E) folder . Yes to upload the photos they had to host them on an FTP, copy the link text and copy and paste these links into a box, I would look like a fool. No posting the solution because from the moment we need to modify some of the core Odoo is not a valid option for everyone, and it's not doing anything fancy. However, OpenERP 7 runs well, need to modify 4 lines, and Odoo 8 also to modify a single line ... the most curious is that the lines change to work on OpenERP 7 are now part of the core of Odoo 8 out the box.

sameer alhwety

@Vicious : can you mention the line in Odoo to make the binary field takes more than file ?

Avatar
AbdelAli MERZOUGUI
Beste antwoord

I've looking for the same functionality, and i inspired from 'Vicious' answer about werkzeug accepting just one file at once, 

In fact, my goal was uploading different images on product profile, since i could not upload but one file at the time, I suited the next procedure:

1- put images in a zip file

2- upload the zip file 

3- get images in memory

4- create images 

That's it, 

Hope that could help you guys

1
Avatar
Annuleer
Avatar
tansadio
Beste antwoord

Hi, I have this error when i upload a image:

image_data = upload.read()

AttributeError: 'unicode' object has no attribute 'read'

When i call my controllers:

The variable request.params['upload'] contains " <FileStorage: u'ir_attachment_117.jpeg' ('image/jpeg')>", 

I want update field product.template image with this image ir_attachment_117.jpeg. 

I need your HELP!

0
Avatar
Annuleer
Vicious
Auteur

I post a new anwser!

Vicious
Auteur

I post a new anwser!

tansadio

Thanks for your answer!

Avatar
yuri
Beste antwoord

Vicious, would you like to share the solution even if modify the core I don't mind.

0
Avatar
Annuleer
Vicious
Auteur

i post a new anwser

Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
Is it possible to upload multiple images for main image of the product? Opgelost
product image upload multiple images
Avatar
Avatar
Avatar
Avatar
4
jan. 23
19443
Upload image from website to backend (contact us form)
upload images contactus
Avatar
Avatar
1
nov. 23
8669
I Want to upload multiple files in my module Opgelost
upload multiple odoo odoo13
Avatar
Avatar
1
nov. 21
16635
[Odoo 14] - Model is not updating via Controller
widget models controllers v14
Avatar
Avatar
1
sep. 21
5380
Images corrupted after upload
upload debian images odoo10
Avatar
Avatar
3
nov. 17
4898
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now