콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
7279 화면

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.

아바타
취소
관련 게시물 답글 화면 활동
1
12월 22
5432
write() vs update() 해결 완료
4
9월 20
41005
2
11월 19
3137
1
4월 19
9712
2
8월 17
7786