Search Here

Upload Image (Files Attachment) in Odoo Website

In this article I am going to teach you how to add or upload attachment or file (doc, excel, zip, jpg, png etc) from odoo website or web page.


Add an attachement (file) from odoo website.

To upload files through web page you have to create a template and odoo controller.

upload_file_attachment_in_odoo_website.xml



upload_file_attachment_in_odoo_website.py



Code Description:

In above code snippet we have created an odoo template, and in that template we have created a HTML form tag, and set the action of that form as our odoo controller route. We have also take three input type fields and a submit button. When user clicks on submit button the form action goes to our odoo controller and save the attachment file in "attachment" model.

Post a Comment

9 Comments

  1. Hello, can you share with us github link for code?
    Thank you

    ReplyDelete
  2. how to display this field in website

    ReplyDelete
  3. in your code error: .py code: row:15 'res_model':'model.model', - you missed " ' "

    ReplyDelete
  4. Hi I Tried this code but "file = post.get('attachment')" is returning a string object.
    when i try attachment = file.read() its says str object has no attribute read()

    ReplyDelete
  5. Hi file = post.get('attachment') is giving me string object and when i try attachment = file.read() it says
    str object has no attribute read()

    ReplyDelete
  6. i am only able to attach only 1 file not multiple any specific reason?

    ReplyDelete