Hi all,
I am familiar with the ORM API and how to use to create new rows in models,
However, when there is a field which is an image (type: binary), how are we supposed to update its contents through the API?
Thanks.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hi all,
I am familiar with the ORM API and how to use to create new rows in models,
However, when there is a field which is an image (type: binary), how are we supposed to update its contents through the API?
Thanks.
Hi Alejandro:
Below Code Update One Product using Odoo XMLRPC you can change product_id and file_path
import base64
# Odoo API authentication
product_id=13
file_path = "/home/Estain/Documents/example.jpg"
with open(file_path, 'rb') as f:
data = f.read()
img = base64.b64encode
encoded_image_data = base64.b64encode(data)
ImageSend = encoded_image_data.decode('ascii')
# Update product record with new image
product = models.execute_kw(db, uid, password, 'product.template', 'write', [[product_id], {'image_1920': ImageSend,}])
How about attach to filestore, instead of database binary field ?
The code is fine, but the line "img = base64.b64encode" can be skipped
Hi Alejandro: You can try using python's base64 module to encode the content and pass it to the api.
Luo tili jo tänään nauttiaksesi yksinoikeusominaisuuksista ja osallistuaksesi mahtavaan yhteisöömme!
RekisteröidyAiheeseen liittyviä artikkeleita | Vastaukset | Näkymät | Toimenpide | |
---|---|---|---|---|
|
1
jouluk. 22
|
5672 | ||
write() vs update()
Ratkaistu
|
|
4
syysk. 20
|
41854 | |
|
2
marrask. 19
|
3339 | ||
|
1
huhtik. 19
|
9996 | ||
|
2
elok. 17
|
8008 |