简体   繁体   中英

Update Images for odoo in PostgreSQL

may I ask you, which format uses Odoo to display images for Products and how to update product images directly into PostgreSQL for Odoo from Python?

I use

cursor.execute('select image_medium from product_product where id = 58')
(file_data) = cursor.fetchone()[0]
writeImage(file_data)
conn.commit()

and can not open file in any image editor after saving to disk.

Alternatively,

data = readImage()
binary = psycopg2.Binary(data)
cursor.execute('update product_product set image_small = %s where id = 57', (binary,))
conn.commit()

makes product could not be opened anymore in Odoo.

Any answer greatly appreciated!

You can use base64 methods encodestring() and decodestring()

Eg:

img = base64.decodestring(file_data)
writeImage(img)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM