Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


how to download file from files which are uploaded by "fields.Binary()" by python code?

on 7/17/16, 10:21 AM 383 views

I want to user upload excel file by "fields.Binary()";

when the user click a certain button, this excel file will be downloaded on server; and then use "xlrd.open_workbook(filename[0])" to get the excel data and do the next doings;

Nikunj Antala
On 7/18/16, 1:04 AM


Odoo already have method for download file from binary data.

    @http.route('/web/binary/saveas', type='http', auth="public")


    def saveas(self, model, field, id=None, filename_field=None, **kw):



This method available on '/web/controllers/main.py'

You can use this method by pass parameter in url.


URL : localhost:8069/web/binary/saveas?model=ir.attachment&field=datas&filename_field=datas_fname&id=103

Using this url odoo will give you data of field datas from ir.attachment model of record id is 103.

------------------------- Code is For reading Excel file that store in Binary format--------------------------

import base64

from openerp import api, fields, models, _

from openpyxl import load_workbook

class ExcelRead(models.TransientModel):

     _name = "excel.read"



     def import_file(self):

        data_file_p = open('/tmp/test.xlsx','w')



         wb = load_workbook('test.xlsx')

         ws = wb['big_data']

         for row in ws.rows:

             for cell in row:


Hope this helps.

Thanks for your reply;

In the fact I want to get the data from the uploaded excel file of "fields.Binary()";

the code:




Now I have uploaded an excel file to "filedata";

My question: how shall I get the the first column data of the Excel file from "filedata"?

on 7/18/16, 1:51 AM

is that file type of csv ?

Nikunj Antala
on 7/18/16, 2:31 AM

Here i have update my answer and add code for read excel file that store in Binary format.

Nikunj Antala
on 7/18/16, 2:48 AM

Thank you very much, Antala,

your reply resolves my problems absolutely.

Thanks for your time, your efforts and your patience.

on 7/18/16, 9:21 AM
On 7/20/16, 10:10 PM

Now I have import excel data from user's terminal and shall I write the modified data back to user's terminal as excel file?

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 7/17/16, 10:21 AM
Seen: 383 times
Last updated: 7/20/16, 10:10 PM