$ 100.38
S3 Attachment Storage With Private Url
Upload attachments on Amazon S3 with private url. User can access file when url used signed_url
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 → Orders -> Quotation/Orders menu and open an form view. Upload any file in Attachments. All files expire in 15 minute.
At this moment in the Settings → Database Structure → Attachments menu the attachments will be created with the corresponding private 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.
After 15 minute expire time, users cannot access file.
If user want to access files, click button "Refresh Url Attachments". The system will create new url with new expire time.
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', ['sale.order'])]
) - 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
14.0 community
S3 Attachment Storage Private Url
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
Configuration
- Activate developer mode
- Open menu Settings >> Technical >> 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
- s3.endpoint_url: optional parameter for s3-compatible storage. E.g.
- s3.obj_url: optional parameter for s3-compatible storage. E.g.
Alternatively, you can set the parameters via environmental variables: S3_BUCKET, S3_CONDITION, S3_ACCESS_KEY_ID, S3_SECRET_KEY, S3_ENDPOINT_URL, S3_OBJ_URL
The settings are also available from the Settings >> Technical >> Database Structure >> S3 Settings.
S3
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.
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 >> Sale Order menu some image for your product. By doing this you have uploaded file on your s3 storage.
Upload existing attachments
- There are 2 ways to upload existing attachments: 1. Open odoo shell and run env["ir.attachment"].force_storage_s3() 2. Go to the Settings >> Technical >> Database Structure >> S3 Settings menu and click on the [Upload existing attachments] button there
Please log in to comment on this module