1

In odoo 13 i have a field example:

birthday_picture = fields.Image(string='Birthday Picture')

i want to add birthday_picture image to be added in email template also which i declared in xml, i have added <img> tag and added still the image is not reflecting below i have shared the line

<div>
    <img src="${'/birthday_picture.png=%s' % object.birthday_picture}" style="width: 60px; height: 60px"/><br/>
</div>

please let me know where i am doing wrong

2 Answers 2

1

If birthday_picture must be dynamic (this means the same email template may render different images) you should consider using fields.Binary

fields.Binary stores a binary file in odoo filesystem and returns a base64 encoded string.

birthday_picture = fields.Binary(string='Birthday Picture')
<img src="${'data:image/png;base64,%s' % object.birthday_picture}" style="width: 60px; height: 60px"/>

In case birthday_picture is always the same (so it is static) best solution would be to create an ir.attachment, set it as public and render into src it's url

Another option would be to manually convert your file into base64 using an online tool and replace src value with the encoded string.

Sign up to request clarification or add additional context in comments.

5 Comments

Yes Brother i want the image dynamically, and as you sid above i did try this but still doesnot return image which i provide in binary field
Can you debug email raw body in order to understand what it is printing instead of the base64 string? Also are you sure the model selected in mail.template is the same model where you added birthday_picture field? Try printing object.birthday_picture into the email template to further investigate
yeah i am sure birthday_picture is in the same model as provided in mail.template, also i already checked what is printing instead of base64 string, it is printing the binary format of the image.
This means binary data must be first converted to base64. You can use image_data_uri or to_text qweb helper functions to obtain this. For example: ${'data:image/png;base64,%s' % image_data_uri(object.birthday_picture)}
No still i cannot see the template to reflect the image however i already solved that
0

Actually i have added this:

<p>
    <img src="/web/image/birthday.reminder/${object.id}/birthday_picture/"/>
</p>

which doesnot reflect the image in template but when i looked for undelivered email from techncal > email. by removing force_send from code i can see my image reflected on it.

however i already searched that the email doesnot support base64 images but there is a tweak to do it as well. here is the link which descried the tweak

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.