Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Uploading an image through web services

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
9 Réponses
14854 Vues
Avatar
Kelly Mulumbi

I'm relatively new to odoo and i would like to upload an image using the XML RPC web service

image = open('max.png', 'rb')
imageBase64 = base64.b64encode(image)
# Updating record
id = models.execute_kw(db, uid, password, 'hr.employee', 'write', [
                       [uid], {'image': imageBase64, 'job_title': "test"}])

The above code gives me the following error:

 TypeError: a bytes-like object is required, not '_io.BufferedReader'

1
Avatar
Ignorer
Sehrish

Check odoo customization tips: https://learnopenerp.tumblr.com/

Hope this will helps

Kelly Mulumbi
Auteur

@Sehrish.. Thank you for your quick response.

Unfortunately the link doesn't contain any information about XML RPC which is what i'm trying to use to upload the images

Sehrish

Check this one: http://learnopenerp.blogspot.com/2019/10/connecting-to-odoo-using-xml-rpc.html

Avatar
Kelly Mulumbi
Auteur Meilleure réponse

The following solution finally worked for me:

After encoding the image into base64, I decoded it into ascii and sent the decoded ascii value to the database:

withopen("max.jpg", "rb") as image:
  BinaryImage = client.Binary(image.read())
  BytesImage = BinaryImage.data
  ImageBase64 = base64.b64encode(BytesImage)
  ImageSend = ImageBase64.decode('ascii')
 
  models.execute_kw(db, uid, password, 'hr.employee', 'write',
  [[1], {'image': ImageSend, 'job_title': 'Test Title'}])
4
Avatar
Ignorer
Chandni Gandhi

Perfect! Worked for me too.

Thanks :)

Avatar
Andres Brigard
Meilleure réponse

Thanks Yenthe. The code I am using to write through the 

execute('res.partner', 'write', [6], {'image': imageBase64})

 Or using OdooRPC

model.browse(6).write({'image': imageBase64)

In both cases I get the following error:

xmlrpc.client.Fault: <Fault 'Binary' object is not subscriptable: 'Traceback (most recent call last):
File "/home/odoo/odoo12/odoo/odoo/addons/base/controllers/rpc.py", line 60, in xmlrpc_1
response = self._xmlrpc(service)
File "/home/odoo/odoo12/odoo/odoo/addons/base/controllers/rpc.py", line 49, in _xmlrpc
result = dispatch_rpc(service, method, params)
File "/home/odoo/odoo12/odoo/odoo/http.py", line 120, in dispatch_rpc
result = dispatch(method, params)
File "/home/odoo/odoo12/odoo/odoo/service/model.py", line 40, in dispatch
res = fn(db, uid, *params)
File "/home/odoo/odoo12/odoo/odoo/service/model.py", line 98, in wrapper
return f(dbname, *args, **kwargs)
File "/home/odoo/odoo12/odoo/odoo/service/model.py", line 185, in execute
res = execute_cr(cr, uid, obj, method, *args, **kw)
File "/home/odoo/odoo12/odoo/odoo/service/model.py", line 169, in execute_cr
result = odoo.api.call_kw(recs, method, args, kw)
File "/home/odoo/odoo12/odoo/odoo/api.py", line 759, in call_kw
return _call_kw_multi(method, model, args, kwargs)
File "/home/odoo/odoo12/odoo/odoo/api.py", line 746, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/home/odoo/odoo12/odoo/addons/partner_autocomplete/models/res_partner.py", line 183, in write
res = super(ResPartner, self).write(values)
File "/home/odoo/odoo12/odoo/odoo/addons/base/models/res_partner.py", line 563, in write
tools.image_resize_images(vals, sizes={'image': (1024, None)})
File "/home/odoo/odoo12/odoo/odoo/tools/image.py", line 302, in image_resize_images
vals.update(image_get_resized_images(vals[big_name],
File "/home/odoo/odoo12/odoo/odoo/tools/image.py", line 292, in image_get_resized_images
return_dict[big_name] = image_resize_image_big(base64_source, avoid_if_small=avoid_resize_big, size=size_big)
File "/home/odoo/odoo12/odoo/odoo/tools/image.py", line 168, in image_resize_image_big
return image_resize_image(base64_source, size, encoding, filetype, avoid_if_small)
File "/home/odoo/odoo12/odoo/odoo/tools/image.py", line 66, in image_resize_image
if size == (None, None) or base64_source[:1] == b'P':
TypeError: 'Binary' object is not subscriptable
Any advice to overcome this problem please?
Thanks Andres
0
Avatar
Ignorer
dino liu

Hi Andres,

please try convert imageBase64 to str, like this imageBase64String = imageBase64.decode('ascii')

or just imageBase64String = str(imageBase64)

then transfer data with imageBase64String

I countered this issue, and figure this out after set debugging on Odoo server

Avatar
Yenthe Van Ginneken (Mainframe Monkey)
Meilleure réponse

Hi Kelly,

I think you're missing the option to actually reads out the bytes of the file, not just the image object itself. Try this:

with open(os.path.join(base_path, 'max.png'), "rb") as attachment_file:
    imageBase64 = base64.b64encode(attachment_file.read())
id = models.execute_kw(db, uid, password, 'hr.employee', 'write', [[uid], {'image': imageBase64, 'job_title': "test"}])


Regards,

Yenthe

0
Avatar
Ignorer
Kelly Mulumbi
Auteur

Hi Yenthe,

With that solution i get a different error:

'TypeError: Binary Object is not subscriptable'

(this is currently where i'm stuck at)

Kelly Mulumbi
Auteur

This is a copy of the code from my terminal:

xmlrpc.client.Fault: <Fault 1: 'Traceback (most recent call last):\n File "/home/odoo/src/odoo/odoo/addons/base/controllers/rpc.py", line 63, in xmlrpc_2\n response = self._xmlrpc(service)\n File "/home/odoo/src/odoo/odoo/addons/base/controllers/rpc.py", line 43, in _xmlrpc\n result = dispatch_rpc(service, method, params)\n File "/home/odoo/src/odoo/odoo/http.py", line 120, in dispatch_rpc\n result = dispatch(method, params)\n File "/home/odoo/src/odoo/odoo/service/model.py", line 39, in dispatch\n res = fn(db, uid, *params)\n File "/home/odoo/src/odoo/odoo/service/model.py", line 153, in execute_kw\n return execute(db, uid, obj, method, *args, **kw or {})\n File "/home/odoo/src/odoo/odoo/service/model.py", line 97, in wrapper\n return f(dbname, *args, **kwargs)\n File "/home/odoo/src/odoo/odoo/service/model.py", line 160, in execute\n res = execute_cr(cr, uid, obj, method, *args, **kw)\n File "/home/odoo/src/odoo/odoo/service/model.py", line 149, in execute_cr\n return odoo.api.call_kw(recs, method, args, kw)\n File "/home/odoo/src/odoo/odoo/api.py", line 749, in call_kw\n return _call_kw_multi(method, model, args, kwargs)\n File "/home/odoo/src/odoo/odoo/api.py", line 736, in _call_kw_multi\n result = method(recs, *args, **kwargs)\n File "/home/odoo/src/odoo/addons/hr_holidays/models/hr.py", line 196, in write\n res = super(Employee, self).write(values)\n File "/home/odoo/src/odoo/addons/hr/models/hr.py", line 267, in write\n tools.image_resize_images(vals)\n File "/home/odoo/src/odoo/odoo/tools/image.py", line 310, in image_resize_images\n avoid_resize_big=True, avoid_resize_medium=False, avoid_resize_small=False, sizes=sizes))\n File "/home/odoo/src/odoo/odoo/tools/image.py", line 297, in image_get_resized_images\n return_dict[big_name] = image_resize_image_big(base64_source, avoid_if_small=avoid_resize_big, size=size_big)\n File "/home/odoo/src/odoo/odoo/tools/image.py", line 173, in image_resize_image_big\n return image_resize_image(base64_source, size, encoding, filetype, avoid_if_small)\n File "/home/odoo/src/odoo/odoo/tools/image.py", line 66, in image_resize_image\n if size == (None, None) or base64_source[:1] == b\'P\':\nTypeError: \'Binary\' object is not subscriptable\n'>

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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