S3 Attachment Storage
by IT-Projects LLC https://twitter.com/OdooFree , Ildar Nasyrov https://twitter.com/OdooFreeIncluded Dependencies | Show |
Lines of code | 986 |
Technical Name |
ir_attachment_s3 |
License | See License tab |
Website | https://itpp.dev |
Also available in version | v 9.0 v 10.0 v 12.0 v 14.0 v 13.0 |
S3 Attachment Storage
Upload attachments on Amazon S3
Features:
- The module allows to upload the attachments in Amazon S3 automatically without storing them in Odoo database. It will allow to reduce the load on your server. Attachments will be uploaded on S3 depending on the condition you specified in Odoo settings. So you can choose and manage which type of attachments should be uploaded on S3.
- It is useful in cases where your database was crashed, because you will be able to easily restore all attachments from external storage at any time.
- The possibility to use one external storage for any number of databases.
How it works
E.g., go to Sales → Products menu and open an item. Upload any images to the product.

At this moment in the Settings → Database Structure → Attachments menu the attachments will be created with the corresponding URL.

Then open Amazon S3 bucket and see uploaded attachments.

The attachments will be loaded to Odoo DB from S3 server by using URL and they will not be stored in your DB.




Configuration
Before using you need to make some configuration:
- Install boto3 library and get credentials for it by using this quickstart instruction https://boto3.readthedocs.io/en/latest/guide/quickstart.html
- Grant access to your S3 bucket using this instruction http://mikeferrier.com/2011/10/27/granting-access-to-a-single-s3-bucket-using-amazon-iam and set bucket as public
- Enable technical features https://odoo-development.readthedocs.io/en/latest/odoo/usage/technical-features.html
-
Open menu Settings → Technical → Database Structure → S3 Settings and specify the following parameters:
-s3.bucket
: the name of your bucket (e.g. mybucket)
-s3.condition
: only the attachments that meet the condition will be sent to S3 (e.g.[('res_model', 'in', ['product.image'])]
) - it is actually the way of specifying the models withfields.Binary
fields that should be stored on S3 instead of local file storage or db. Don't specify anything if you want to store all your attachment data fromfields.Binary
and also ordinary attachments on S3.
-s3.access_key_id
: S3 access key ID
-s3.secret_key
: S3 secret access key - Click on
Upload existing attachments
if you want to upload attachments you had before installation the module

Free Support
You will get free support and assistance in case of any issues
Need our service?
Contact us by email or fill out request form
- apps@it-projects.info
- https://www.it-projects.info/page/website.contactus
- https://m.me/itprojectsllc
- skype@it-projects.info
11.0 community
11.0 enterprise
S3 Attachment Storage
Installation
Using this quickstart instruction install boto3 library and get credentials for it
Using this instruction grant access to your s3 bucket
Set your S3 bucket as public
Optionaly, add following parameter to prevent heavy logs from boto3 library:
--log-handler=boto3.resources.action:WARNING
IAM
Minimal access policy for s3 credentials are as following:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "s3:PutObject", "s3:CreateBucket", "s3:GetBucketLocation", "s3:PutObjectAcl" ], "Resource": [ "arn:aws:s3:::YOUBUCKETNAMEHERE", "arn:aws:s3:::YOUBUCKETNAMEHERE/*" ] } ] }
You can also remove "s3:CreateBucket" if bucket already exists.
Configuration
- To enable the feature of linking existing urls to binary fields:
- Start Odoo with --load=web,ir_attachment_url or set the server_wide_modules option in The Odoo configuration file:
[options] # (...) server_wide_modules = web,ir_attachment_url # (...)
- Enable technical features
- Open menu Settings >> Parameters >> System Parameters and specify the following parameters there
- s3.bucket: the name of your bucket (e.g. mybucket)
- s3.condition: only the attachments that meet the condition will be sent to s3 (e.g. [('res_model', 'in', ['product.image'])]) - it is actually the way of specifying the models with fields.Binary fields that should be stored on s3 instead of local file storage or db. Don't specify anything if you want to store all your attachment data from fields.Binary and also ordinary attachments on s3.
- s3.access_key_id: S3 access key ID
- s3.secret_key: S3 secret access key
The settings are also available from the Settings >> Technical >> Database Structure >> S3 Settings.
You can also set these parameters using environment variables
Mapping Environment variables to Odoo System parameters:
- S3_BUCKET: it is s3.bucket parameter
- S3_CONDITION: it is s3.condition parameter
- S3_ACCESS_KEY_ID: it is s3.access_key_id parameter
- S3_SECRET_KEY: it is s3.secret_key parameter
NOTE: if you simultaneously set parameters both in the Environment variables and in the Odoo System parameters, then the Odoo System parameters have the highest priority.
Usage
Depending on what you have in the s3.condition setting, some or all attachments will be uploaded on your s3. For example upload by editing product template from Sales >> Product menu some image for your product. By doing this you have uploaded image on your s3 storage. In this case you should also install ir_attachment_url module to be able to see products' images in odoo backend. Because by default odoo doesn't use urls in its backend. It uses only local stored files or stored db data.
Upload existing attachments
- To upload existing attachments go to the Settings >> Technical >> Database Structure >> S3 Settings menu and click on the [Upload existing attachments] button there
- To add link of existing S3 bucket object to binary fields of existing odoo records:
- Take Link urls from Amazon. If you open Overview of the object on Amazon you should see it at the bottom of the page
- make sure that you have properly configured your odoo, see the Configuration section of this instruction once again in the To enable feature of linking... part
- to link objects one-by-one from an odoo backend (this option is only available for images attachments):
- In any place where you can upload images to odoo (i.e. from Sales >> Sales >> Products when you select a product and push [Edit] button there and hover your mouse pointer under the place on a form view where an image should be) along with standard pencil and trash bin buttons you can see the additional [@] button. Click on this button.
- Copy-paste your url for image and click [Save] button
- to link objects in batch you may use default import/export feature in odoo:
- for example, export records of model product.template. Choose image field in the export dialog and save in file.
- open the file with your favorite text editor and paste urls into image column there
- import records from the edited CSV file
- now when you open from Sales >> Sales >> Products your product form, you should see the image you specified by url in the file
GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
Please log in to comment on this module