I am trying to retrieve image from XMLRPC.
I do:
record = api.execute_kw(db, uid, pwd, 'product.template', 'read', [[id]], {'fields': ['id', 'name', 'image']})
sub_record = dict((k, record[0][k]) for k in ('id', 'name', 'image'))
print sub_record['image']
If I print the image using print sub_record['image']
then I get:
[...]
eSYH+sOdc3UW9XB1SzWvVCtcI0PfKdoYe9Suf/3116+mMGyhLTg/yedEprt6nOI3eNOxT9t6SzMN
Cj8tT5Lp9eqmsvmu1reytnROwdFvdWvkwsLihqqJ0+49ZW8nu9tzDb+RkT2f5tWpjpf8yZaJzyYW
SPN8f22Vnp9pr+mA7KzqwltQk8QGT02ViY6bpvBdTZqJH5uafxJcHFzPp8nB6KTYUlMq4jS3mAkm
[...]
So basically several carriage returns are inserted in the middle of the image base64 string.
How can I use that string to display it in an <img>
html tag?
Do I have to remove these carriage returns first?
Basically you get the base64 string from the odoo. You don't need to modify it just add the data:image/jpeg;base64,
content before the base64 string. Now you have to add whole updated string in image tag as below.
<img src="data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />
Also Check this https://jsfiddle.net/Xadvz/7883/ example in which I have created image from the base64 string of demo product "Ink Cartridge" for further reference.
I hope this will help you!