Download Binary file in Odoo 10

To download any binary file in Odoo10 following is the link:

http://127.0.0.1:8069/web/content?model=<module_name>&field=<field_name>&filename_field=<field_filename>&id=<object_id>
module_name   - the name of the model with the Binary field
field_name        - the name of the Binary field
object_id           - id of the record containing particular file.
field_filename   - name of a Char field containing file's name (optional).
So if you want to call a function on button click and download the file, code is as follow:
file_url = "http://127.0.0.1:8069/web/content?model=<module_name>&field=<field_name>&filename_field=<field_filename>&id=<object_id>"
return {
    'type': 'ir.actions.act_url',
    'url': file_url,
    'target': 'new'
}

In Reports or web page, you can use it as:


<t t-foreach="files" t-as="f">
    <tr>
        <td><t t-esc="f.name"/></td>
        <td><a t-attf-href="/web/content?model=<module_name>&field=<field_name>&filename_field=<field_filename>&id=<object_id>">Download</a></td>
    </tr>
</t>

Where files is a list of files

Comments

Popular posts from this blog

How to learn data structure effectively

How to resolve some issue while Installing Moodle Ubuntu 16.04 using Xampp

How to change phpmyadmin URL in Xampp Ubuntu and how to solve 'New Security Concept while accessing Phpmyadmin - Xampp' ?