如何通过xml-rpc向odoo发送mysql的镜像到postgresql



我试图开发一个连接器,将我的电子商务平台连接到Odoo。目前我有一个关于图像的问题。我的图片在我的电子商务平台mysql中,如下所示:catalog/image/toto.jpg

我想在odoo平台(产品)中插入这个图像,如何做到这一点,只需在xml-rpc代码中插入以下内容:http://www.mydomain/catalog/image/toto.jpg?

谢谢。

Odoo源代码中的一条注释:

    # Binary values may be byte strings (python 2.6 byte array), but
    # the legacy OpenERP convention is to transfer and store binaries
    # as base64-encoded strings. The base64 string may be provided as a
    # unicode in some circumstances, hence the str() cast in symbol_f.
    # This str coercion will only work for pure ASCII unicode strings,
    # on purpose - non base64 data must be passed as a 8bit byte strings.

所以您需要读取图像文件,并可能用base64对其进行编码。结果传递到二进制字段。

如果你的图像在文件系统上,它会像这样:

import base64
img = open('path to my img', 'rb').read()
data = base64.b64encode(img)
# Write data to odoo

此外,您可以使用openerp_proxy项目来简化与xml-rpc相关的工作

最新更新