Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

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

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
imagepython3v15
1 Odpowiedz
8568 Widoki
Awatar
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
Awatar
Odrzuć
Awatar
Waleed Ali Mohsen
Najlepsza odpowiedź

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
Awatar
Odrzuć
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

Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
How can I insert a list of values as the title of an excel sheet? Rozwiązane
python3 v15
Awatar
1
gru 22
3574
Python3: How to get the article information of a fabrication order Rozwiązane
python3 v15
Awatar
Awatar
2
lis 22
3106
How to reset a existing cookie in odoo using python
python3 v15
Awatar
Awatar
1
mar 22
4202
How to transfer data in invoice to register payment in odo v15 ?
python3 v15
Awatar
Awatar
2
mar 22
3937
Upload product image to Amazon S3 bucket
image aws v15
Awatar
Awatar
1
lip 25
2660
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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