Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

How to get image from field.Image in Odoo15 from python

Odoberať

Get notified when there's activity on this post

This question has been flagged
imagepython3v15
1 Odpoveď
8562 Zobrazenia
Avatar
Aldi Mulyawan

Hello everyone, i am trying to get some image from odoo Image field but i always get the image size value like for example ( 47.99 Kb ). i want to get the image data, i dont care if its binary or anything (i can convert it later so yeah). Any help would be appreciated. Thanks!


For example this is the image field

image_image = fields.Image(string='Image',readonly='True',help='Generated Image' )

or this

image_variant_1920 = fields.Image("Variant Image", max_width=1920, max_height=1920)  

0
Avatar
Zrušiť
Avatar
Waleed Ali Mohsen
Best Answer

To get the binary data for an image field, you need to decode it using base64.b64decode(Pass the image field) 

import base64
if self.image_1920:
    base64.b64decode(self.image_1920)

3
Avatar
Zrušiť
Aldi Mulyawan
Autor

Thanks for the reply, but i got this error. do note that template is one of the record of product.template model

line 54, in _compute_image_tes
image_data = base64.b64decode(template.image_1920)
File "/usr/lib/python3.8/base64.py", line 87, in b64decode
return binascii.a2b_base64(s)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/smam/odoo15/odoo/http.py", line 643, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/smam/odoo15/odoo/http.py", line 301, in _handle_exception
raise exception.with_traceback(None) from new_cause
binascii.Error: Incorrect padding

Waleed Ali Mohsen

Please share your code

Waleed Ali Mohsen

try to check if image_1920 has value:
if template.image_1920:
image_data = base64.b64decode(template.image_1920)

Aldi Mulyawan
Autor

image_1920 do have a value, but the value only come out as image size (one of the product, different product have different size). as i stated above for example is 47.99 Kb or maybe b'47.99 Kb' if i didn't decode it first

Aldi Mulyawan
Autor

@api.depends('image_1920','company_id.key_imgbb')
def _compute_image_tes(self):
for template in self:
image_data = base64.b64decode(template.image_1920)
template.image_tes = str(image_data)

note : image_tes is string field

Waleed Ali Mohsen

I tested it with write method and it's giving a value

def write(self,vals):
super().write(vals)
print(base64.b64decode(self.image_1920))

Waleed Ali Mohsen

It seems it's not working with compute method, another solution to use image url:

@api.depends('image_1920', 'company_id.key_imgbb')
def _compute_image_tes(self):
for template in self:
url = template.get_base_url() + "/web/image/product.template/%s/image_1920" % template.id
template.image_tes = str(base64.b64encode(urlopen(url).read()))

Aldi Mulyawan
Autor

thanks for your answer, i will try it. for the urlopen, what is the library or what do i need to import so i can use the urlopen?

Waleed Ali Mohsen

from urllib.request import urlopen

Aldi Mulyawan
Autor

Tried with link, it works. thank you so much!

Aldi Mulyawan
Autor

link = image url*

Aldi Mulyawan
Autor

One more thing, i got some error because the img sent is some kind of template image and not product image. do you know how to fix it? here is the template image that got sent https://i.ibb.co/t2SfQns/79912e68b28b.png

Waleed Ali Mohsen

Make sure the product has an image

Aldi Mulyawan
Autor

It has an image, i think its because the urlopen library isnt registered as user so odoo gave template image. because when i try to open the image url using browser with logged in account, i can see the image. but when i try to open with incognito (so logged out account) then i got that template image

Aldi Mulyawan
Autor

Strangely i dont face this problem when i last sent my message, but now i got the problem

Waleed Ali Mohsen

If ecommerce is installed you can get the image

Aldi Mulyawan
Autor

can i get without ecommerce? not using urlopen but using odoo function or something?

Waleed Ali Mohsen

You need to open access to model product.product and product.template. you can add security as below:

access_product_product_public,product.product.public,product.model_product_product,,1,0,0,0
access_product_template_public,product.template.public,product.model_product_template,,1,0,0,0

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrácia
Related Posts Replies Zobrazenia Aktivita
How can I insert a list of values as the title of an excel sheet? Solved
python3 v15
Avatar
1
dec 22
3573
Python3: How to get the article information of a fabrication order Solved
python3 v15
Avatar
Avatar
2
nov 22
3103
How to reset a existing cookie in odoo using python
python3 v15
Avatar
Avatar
1
mar 22
4196
How to transfer data in invoice to register payment in odo v15 ?
python3 v15
Avatar
Avatar
2
mar 22
3935
Upload product image to Amazon S3 bucket
image aws v15
Avatar
Avatar
1
júl 25
2658
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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