Skip to Content
Menu
This question has been flagged
6535 Views

Hello everyone 

Thanks for your help in advanced, 

I would like to attache image in my web form and let it appear in binary field in odoo11, below is my code but something is wrong with it, right now the attached image goes to ir.attachments only.

HTML code for attached button 

<div class="form-group form-field">
    <div class="col-md-3 col-sm-4 text-right-not-xs">
        <label class="control-label" for="image_attach"> Image </label>
    </div>
    <div class="col-md-7 col-sm-8">
        <input type="file" class="form-control o_website_form_input" method="post" enctype="multipart/form-data" name="image_attach"/>
    </div>
</div>


PY code for binary field

image_attach = fields.Binary('Image')

i have tried to add attachment=True nothing happened as well.


XML code for the binary field 

<field name=" image_attach " widget="image" class="oe_left oe_avatar"/>


http controller code

from odoo import http

class Image(http.Controller):
    def index(self, **kw):
        vals = {}
        if post['image_attach']:
            vals.update({'image_attach': base64.encodestring(post['image_attach'].read())})
        request.registry['hr.image'].write(cr, uid, vals)


Hope anyone could help me to find out what is wrong in my coding and solve this issue, thanks.

Avatar
Discard
Author

hello Sehrish, thank you for your help, in this link he is saying; the code save the attachement file in "ir.attachment" model. this is already working in my code the attachment goes to ir.attachment but i need to take this attachment to binarry field.