odoo-addon-fs-attachment-s3 16.0.2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of odoo-addon-fs-attachment-s3 might be problematic. Click here for more details.
- odoo/addons/fs_attachment_s3/README.rst +178 -0
- odoo/addons/fs_attachment_s3/__init__.py +1 -0
- odoo/addons/fs_attachment_s3/__manifest__.py +21 -0
- odoo/addons/fs_attachment_s3/i18n/fs_attachment_s3.pot +48 -0
- odoo/addons/fs_attachment_s3/models/__init__.py +2 -0
- odoo/addons/fs_attachment_s3/models/fs_storage.py +55 -0
- odoo/addons/fs_attachment_s3/models/ir_attachment.py +82 -0
- odoo/addons/fs_attachment_s3/readme/CONFIGURE.md +64 -0
- odoo/addons/fs_attachment_s3/readme/CONTRIBUTORS.md +2 -0
- odoo/addons/fs_attachment_s3/readme/CREDITS.md +4 -0
- odoo/addons/fs_attachment_s3/readme/DESCRIPTION.md +7 -0
- odoo/addons/fs_attachment_s3/static/description/icon.png +0 -0
- odoo/addons/fs_attachment_s3/static/description/index.html +516 -0
- odoo/addons/fs_attachment_s3/tests/__init__.py +1 -0
- odoo/addons/fs_attachment_s3/tests/common.py +63 -0
- odoo/addons/fs_attachment_s3/tests/test_fs_attachment_s3.py +35 -0
- odoo/addons/fs_attachment_s3/views/fs_storage.xml +23 -0
- odoo_addon_fs_attachment_s3-16.0.2.0.0.dist-info/METADATA +195 -0
- odoo_addon_fs_attachment_s3-16.0.2.0.0.dist-info/RECORD +21 -0
- odoo_addon_fs_attachment_s3-16.0.2.0.0.dist-info/WHEEL +5 -0
- odoo_addon_fs_attachment_s3-16.0.2.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
.. image:: https://odoo-community.org/readme-banner-image
|
|
2
|
+
:target: https://odoo-community.org/get-involved?utm_source=readme
|
|
3
|
+
:alt: Odoo Community Association
|
|
4
|
+
|
|
5
|
+
================
|
|
6
|
+
Fs Attachment S3
|
|
7
|
+
================
|
|
8
|
+
|
|
9
|
+
..
|
|
10
|
+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
11
|
+
!! This file is generated by oca-gen-addon-readme !!
|
|
12
|
+
!! changes will be overwritten. !!
|
|
13
|
+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
14
|
+
!! source digest: sha256:c7fa84a6b0932b3673afbfca4f7c1f4c6b8858362c51783043d6c5a360de5282
|
|
15
|
+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
16
|
+
|
|
17
|
+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
|
|
18
|
+
:target: https://odoo-community.org/page/development-status
|
|
19
|
+
:alt: Beta
|
|
20
|
+
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
|
|
21
|
+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
|
22
|
+
:alt: License: AGPL-3
|
|
23
|
+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstorage-lightgray.png?logo=github
|
|
24
|
+
:target: https://github.com/OCA/storage/tree/16.0/fs_attachment_s3
|
|
25
|
+
:alt: OCA/storage
|
|
26
|
+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
|
27
|
+
:target: https://translation.odoo-community.org/projects/storage-16-0/storage-16-0-fs_attachment_s3
|
|
28
|
+
:alt: Translate me on Weblate
|
|
29
|
+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
|
|
30
|
+
:target: https://runboat.odoo-community.org/builds?repo=OCA/storage&target_branch=16.0
|
|
31
|
+
:alt: Try me on Runboat
|
|
32
|
+
|
|
33
|
+
|badge1| |badge2| |badge3| |badge4| |badge5|
|
|
34
|
+
|
|
35
|
+
This module extends the functionality of
|
|
36
|
+
`fs_attachment <https://github.com/OCA/storage/tree/16.0/fs_attachment>`__
|
|
37
|
+
to better support Amazon S3 storage. It includes features such as:
|
|
38
|
+
|
|
39
|
+
- Special handling of X-Accel-Redirect headers for S3 storages.
|
|
40
|
+
- Options for using signed URLs in X-Accel-Redirect. (This is required
|
|
41
|
+
to be able to serve files from a private S3 bucket using
|
|
42
|
+
X-Accel-Redirect without exposing the files publicly.)
|
|
43
|
+
- Enforcing the mimetype of files stored in S3.
|
|
44
|
+
|
|
45
|
+
**Table of contents**
|
|
46
|
+
|
|
47
|
+
.. contents::
|
|
48
|
+
:local:
|
|
49
|
+
|
|
50
|
+
Configuration
|
|
51
|
+
=============
|
|
52
|
+
|
|
53
|
+
On the Odoo instance, go to *Settings* > *Technical* > *Storage* > *File
|
|
54
|
+
Storage*.
|
|
55
|
+
|
|
56
|
+
When you create a new storage for s3 or modify an existing one, when you
|
|
57
|
+
activate the option "Use X-Sendfile To Serve Internal Url", 2 additional
|
|
58
|
+
fields will appear:
|
|
59
|
+
|
|
60
|
+
- **S3 Uses Signed URL For X-Accel-Redirect**: If checked, the
|
|
61
|
+
X-Accel-Redirect path will be a signed URL, which is useful for S3
|
|
62
|
+
storages that require signed URLs for access.
|
|
63
|
+
- **S3 Signed URL Expiration**: The expiration time for the signed URL
|
|
64
|
+
in seconds. This field is only relevant if the previous option is
|
|
65
|
+
checked. By default, it is set to 30 seconds but it could be less
|
|
66
|
+
since the url generated into the X-Accel-Redirect process is directly
|
|
67
|
+
used by the web server to serve the file.
|
|
68
|
+
|
|
69
|
+
The value of these fields can also be set in the server environment
|
|
70
|
+
variables using the keys:
|
|
71
|
+
|
|
72
|
+
- *s3_uses_signed_url_for_x_sendfile*
|
|
73
|
+
- *s3_signed_url_expiration*
|
|
74
|
+
|
|
75
|
+
When the option "Use X-Sendfile To Serve Internal Url" is enabled, the
|
|
76
|
+
system will generate an X-Accel-Redirect header in the response to a
|
|
77
|
+
request to get a file. In the case of S3 storages, it will follow the
|
|
78
|
+
format:
|
|
79
|
+
|
|
80
|
+
.. code:: text
|
|
81
|
+
|
|
82
|
+
X-Accel-Redirect: /fs_x_sendfile/{scheme}/{host}/{path with query if any}
|
|
83
|
+
|
|
84
|
+
Where:
|
|
85
|
+
|
|
86
|
+
- ``{scheme}``: The URL scheme (http or https).
|
|
87
|
+
- ``{host}``: The host of the S3 storage.
|
|
88
|
+
- ``{path with query if any}``: The path to the file in the S3 storage,
|
|
89
|
+
including any query parameters. (Query parameters are set when the
|
|
90
|
+
``s3_uses_signed_url_for_x_sendfile`` option is enabled.)
|
|
91
|
+
|
|
92
|
+
In order to serve files using X-Accel-Redirect, you must ensure that
|
|
93
|
+
your web server is configured to handle these headers correctly. This
|
|
94
|
+
typically involves setting up a location block in your web server
|
|
95
|
+
configuration that matches the X-Accel-Redirect path and proxies the
|
|
96
|
+
request to the S3 storage.
|
|
97
|
+
|
|
98
|
+
For example, if you are using Nginx, you would add a location block like
|
|
99
|
+
this:
|
|
100
|
+
|
|
101
|
+
.. code:: nginx
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
location ~ ^/fs_x_sendfile/(.*?)/(.*?)/(.*) {
|
|
105
|
+
internal;
|
|
106
|
+
set $url_scheme $1;
|
|
107
|
+
set $url_host $2;
|
|
108
|
+
set $url_path $3;
|
|
109
|
+
set $url $url_scheme://$url_host/$url_path;
|
|
110
|
+
|
|
111
|
+
proxy_pass $url$is_args$args;
|
|
112
|
+
proxy_set_header Host $url_host;
|
|
113
|
+
proxy_ssl_server_name on;
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
Unlike the standard implementation of X-Accel-Redirect on non S3
|
|
118
|
+
storages, the S3 implementation does not require a base URL to be set in
|
|
119
|
+
the storage configuration. The X-Accel-Redirect path is constructed
|
|
120
|
+
directly from the S3 storage's URL defined for the connection, the
|
|
121
|
+
directory name as bucket name, and the file path.
|
|
122
|
+
|
|
123
|
+
Bug Tracker
|
|
124
|
+
===========
|
|
125
|
+
|
|
126
|
+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/storage/issues>`_.
|
|
127
|
+
In case of trouble, please check there if your issue has already been reported.
|
|
128
|
+
If you spotted it first, help us to smash it by providing a detailed and welcomed
|
|
129
|
+
`feedback <https://github.com/OCA/storage/issues/new?body=module:%20fs_attachment_s3%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
|
130
|
+
|
|
131
|
+
Do not contact contributors directly about support or help with technical issues.
|
|
132
|
+
|
|
133
|
+
Credits
|
|
134
|
+
=======
|
|
135
|
+
|
|
136
|
+
Authors
|
|
137
|
+
-------
|
|
138
|
+
|
|
139
|
+
* ACSONE SA/NV
|
|
140
|
+
|
|
141
|
+
Contributors
|
|
142
|
+
------------
|
|
143
|
+
|
|
144
|
+
- Laurent Mignon laurent.mignon@acsone.eu (https://www.acsone.eu)
|
|
145
|
+
- Stéphane Bidoul stephane.bidoul@acsone.eu (https://www.acsone.eu)
|
|
146
|
+
|
|
147
|
+
Other credits
|
|
148
|
+
-------------
|
|
149
|
+
|
|
150
|
+
The development of this module has been financially supported by:
|
|
151
|
+
|
|
152
|
+
- ACSONE SA/NV (https://www.acsone.eu)
|
|
153
|
+
- Alcyon Belux
|
|
154
|
+
|
|
155
|
+
Maintainers
|
|
156
|
+
-----------
|
|
157
|
+
|
|
158
|
+
This module is maintained by the OCA.
|
|
159
|
+
|
|
160
|
+
.. image:: https://odoo-community.org/logo.png
|
|
161
|
+
:alt: Odoo Community Association
|
|
162
|
+
:target: https://odoo-community.org
|
|
163
|
+
|
|
164
|
+
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
|
165
|
+
mission is to support the collaborative development of Odoo features and
|
|
166
|
+
promote its widespread use.
|
|
167
|
+
|
|
168
|
+
.. |maintainer-lmignon| image:: https://github.com/lmignon.png?size=40px
|
|
169
|
+
:target: https://github.com/lmignon
|
|
170
|
+
:alt: lmignon
|
|
171
|
+
|
|
172
|
+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|
|
173
|
+
|
|
174
|
+
|maintainer-lmignon|
|
|
175
|
+
|
|
176
|
+
This module is part of the `OCA/storage <https://github.com/OCA/storage/tree/16.0/fs_attachment_s3>`_ project on GitHub.
|
|
177
|
+
|
|
178
|
+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import models
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Copyright 2025 ACSONE SA/NV
|
|
2
|
+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
|
3
|
+
|
|
4
|
+
{
|
|
5
|
+
"name": "Fs Attachment S3",
|
|
6
|
+
"summary": """Store attachments into S3 complient filesystem""",
|
|
7
|
+
"version": "16.0.2.0.0",
|
|
8
|
+
"license": "AGPL-3",
|
|
9
|
+
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
|
|
10
|
+
"website": "https://github.com/OCA/storage",
|
|
11
|
+
"depends": ["fs_attachment"],
|
|
12
|
+
"external_dependencies": {
|
|
13
|
+
"python": [
|
|
14
|
+
"fsspec[s3]",
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
"data": [
|
|
18
|
+
"views/fs_storage.xml",
|
|
19
|
+
],
|
|
20
|
+
"maintainers": ["lmignon"],
|
|
21
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Translation of Odoo Server.
|
|
2
|
+
# This file contains the translation of the following modules:
|
|
3
|
+
# * fs_attachment_s3
|
|
4
|
+
#
|
|
5
|
+
msgid ""
|
|
6
|
+
msgstr ""
|
|
7
|
+
"Project-Id-Version: Odoo Server 16.0\n"
|
|
8
|
+
"Report-Msgid-Bugs-To: \n"
|
|
9
|
+
"Last-Translator: \n"
|
|
10
|
+
"Language-Team: \n"
|
|
11
|
+
"MIME-Version: 1.0\n"
|
|
12
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
|
13
|
+
"Content-Transfer-Encoding: \n"
|
|
14
|
+
"Plural-Forms: \n"
|
|
15
|
+
|
|
16
|
+
#. module: fs_attachment_s3
|
|
17
|
+
#: model:ir.model,name:fs_attachment_s3.model_ir_attachment
|
|
18
|
+
msgid "Attachment"
|
|
19
|
+
msgstr ""
|
|
20
|
+
|
|
21
|
+
#. module: fs_attachment_s3
|
|
22
|
+
#: model:ir.model,name:fs_attachment_s3.model_fs_storage
|
|
23
|
+
msgid "FS Storage"
|
|
24
|
+
msgstr ""
|
|
25
|
+
|
|
26
|
+
#. module: fs_attachment_s3
|
|
27
|
+
#: model:ir.model.fields,help:fs_attachment_s3.field_fs_storage__s3_uses_signed_url_for_x_sendfile
|
|
28
|
+
msgid ""
|
|
29
|
+
"If checked, the storage will use signed URLs for attachments when using "
|
|
30
|
+
"X-Accel-Redirect. This is useful for S3 storage where the file path is not "
|
|
31
|
+
"directly accessible without authentication."
|
|
32
|
+
msgstr ""
|
|
33
|
+
|
|
34
|
+
#. module: fs_attachment_s3
|
|
35
|
+
#: model:ir.model.fields,field_description:fs_attachment_s3.field_fs_storage__s3_signed_url_expiration
|
|
36
|
+
msgid "Signed URL Expiration (seconds)"
|
|
37
|
+
msgstr ""
|
|
38
|
+
|
|
39
|
+
#. module: fs_attachment_s3
|
|
40
|
+
#: model:ir.model.fields,help:fs_attachment_s3.field_fs_storage__s3_signed_url_expiration
|
|
41
|
+
msgid ""
|
|
42
|
+
"The expiration time for the signed URL in seconds. Default is 30 seconds."
|
|
43
|
+
msgstr ""
|
|
44
|
+
|
|
45
|
+
#. module: fs_attachment_s3
|
|
46
|
+
#: model:ir.model.fields,field_description:fs_attachment_s3.field_fs_storage__s3_uses_signed_url_for_x_sendfile
|
|
47
|
+
msgid "Use signed URL for X-Accel-Redirect"
|
|
48
|
+
msgstr ""
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Copyright 2025 ACSONE SA/NV
|
|
2
|
+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
|
3
|
+
|
|
4
|
+
import fsspec.asyn
|
|
5
|
+
|
|
6
|
+
from odoo import api, fields, models
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class FsStorage(models.Model):
|
|
10
|
+
|
|
11
|
+
_inherit = "fs.storage"
|
|
12
|
+
|
|
13
|
+
s3_uses_signed_url_for_x_sendfile = fields.Boolean(
|
|
14
|
+
string="Use signed URL for X-Accel-Redirect",
|
|
15
|
+
help="If checked, the storage will use signed URLs for attachments "
|
|
16
|
+
"when using X-Accel-Redirect. This is useful for S3 storage where the "
|
|
17
|
+
"file path is not directly accessible without authentication.",
|
|
18
|
+
)
|
|
19
|
+
s3_signed_url_expiration = fields.Integer(
|
|
20
|
+
string="Signed URL Expiration (seconds)",
|
|
21
|
+
default=30,
|
|
22
|
+
help="The expiration time for the signed URL in seconds. "
|
|
23
|
+
"Default is 30 seconds.",
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def _server_env_fields(self):
|
|
28
|
+
"""Override to include S3 specific fields."""
|
|
29
|
+
fields = super()._server_env_fields
|
|
30
|
+
fields.update(
|
|
31
|
+
{
|
|
32
|
+
"s3_uses_signed_url_for_x_sendfile": {},
|
|
33
|
+
"s3_signed_url_expiration": {},
|
|
34
|
+
}
|
|
35
|
+
)
|
|
36
|
+
return fields
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def is_s3_storage(self):
|
|
40
|
+
"""Check if the storage is an S3 storage."""
|
|
41
|
+
self.ensure_one()
|
|
42
|
+
return hasattr(self._get_root_filesystem(self.fs), "s3")
|
|
43
|
+
|
|
44
|
+
@api.model
|
|
45
|
+
def _s3_call_generate_presigned_url(self, s3_client, *args, **kwargs):
|
|
46
|
+
"""Generate a presigned URL for S3 operations."""
|
|
47
|
+
# s3fs uses aiobotocore as s3 client, which is asynchronous.
|
|
48
|
+
# We need to run the async function in a synchronous context.
|
|
49
|
+
return fsspec.asyn.sync(
|
|
50
|
+
fsspec.asyn.get_loop(),
|
|
51
|
+
s3_client.generate_presigned_url,
|
|
52
|
+
*args,
|
|
53
|
+
timeout=None,
|
|
54
|
+
**kwargs,
|
|
55
|
+
)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Copyright 2025 ACSONE SA/NV
|
|
2
|
+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
|
3
|
+
from urllib.parse import urlparse
|
|
4
|
+
|
|
5
|
+
from odoo import models
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class IrAttachment(models.Model):
|
|
9
|
+
|
|
10
|
+
_inherit = "ir.attachment"
|
|
11
|
+
|
|
12
|
+
def _storage_write_option(self, fs):
|
|
13
|
+
option = super()._storage_write_option(fs)
|
|
14
|
+
mimetype = self.env.context.get("mimetype")
|
|
15
|
+
if mimetype:
|
|
16
|
+
root_fs = self.env["fs.storage"]._get_root_filesystem(fs)
|
|
17
|
+
if hasattr(root_fs, "s3"):
|
|
18
|
+
option["ContentType"] = mimetype
|
|
19
|
+
return option
|
|
20
|
+
|
|
21
|
+
def _get_x_sendfile_path(self):
|
|
22
|
+
self.ensure_one()
|
|
23
|
+
storage = self.fs_storage_id
|
|
24
|
+
if storage.is_s3_storage:
|
|
25
|
+
return self._get_s3_x_sendfile_path()
|
|
26
|
+
return super()._get_x_sendfile_path()
|
|
27
|
+
|
|
28
|
+
def _fs_use_x_sendfile(self):
|
|
29
|
+
self.ensure_one()
|
|
30
|
+
storage = self.fs_storage_id
|
|
31
|
+
if storage.is_s3_storage:
|
|
32
|
+
return storage.use_x_sendfile_to_serve_internal_url
|
|
33
|
+
return super()._fs_use_x_sendfile()
|
|
34
|
+
|
|
35
|
+
def _get_s3_x_sendfile_path(self):
|
|
36
|
+
"""Generate the X-Accel-Redirect path for S3 storage.
|
|
37
|
+
|
|
38
|
+
This method is used to generate the path for S3 storage when using
|
|
39
|
+
X-Accel-Redirect. It constructs the path based on the S3 bucket and
|
|
40
|
+
file path, ensuring that it is compatible with the S3 storage
|
|
41
|
+
configuration and the Odoo file storage system.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
attachment (IrAttachment): The attachment record for which the
|
|
45
|
+
X-Accel-Redirect path is being generated.
|
|
46
|
+
Returns:
|
|
47
|
+
str: The X-Accel-Redirect path for the S3 storage.
|
|
48
|
+
|
|
49
|
+
The path is formatted as:
|
|
50
|
+
/fs_x_sendfile/<scheme>/<netloc>/<path>
|
|
51
|
+
|
|
52
|
+
where:
|
|
53
|
+
- `<scheme>` is the scheme of the base URL (e.g., 'https').
|
|
54
|
+
- `<netloc>` is the netloc of the base URL (e.g., 's3.amazonaws.com').
|
|
55
|
+
- `<path>` is the path to the file in the S3 bucket, including the
|
|
56
|
+
bucket name
|
|
57
|
+
"""
|
|
58
|
+
fs, storage_code, file_path = self._get_fs_parts()
|
|
59
|
+
storage = self.env["fs.storage"].sudo().get_by_code(storage_code)
|
|
60
|
+
root_fs = storage._get_root_filesystem(fs)
|
|
61
|
+
s3_client = root_fs.s3
|
|
62
|
+
bucket_name = storage.directory_path.strip("/").rstrip("/")
|
|
63
|
+
if storage.s3_uses_signed_url_for_x_sendfile:
|
|
64
|
+
file_url = storage._s3_call_generate_presigned_url(
|
|
65
|
+
s3_client,
|
|
66
|
+
"get_object",
|
|
67
|
+
Params={"Bucket": bucket_name, "Key": file_path},
|
|
68
|
+
ExpiresIn=storage.s3_signed_url_expiration,
|
|
69
|
+
)
|
|
70
|
+
else:
|
|
71
|
+
file_url = (
|
|
72
|
+
f"{s3_client.meta.endpoint_url.rstrip('/')}/"
|
|
73
|
+
f"{bucket_name}/{file_path.lstrip('/')}"
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
parsed_url = urlparse(file_url)
|
|
77
|
+
path = parsed_url.path.strip("/")
|
|
78
|
+
query = parsed_url.query
|
|
79
|
+
redirect_path = f"/fs_x_sendfile/{parsed_url.scheme}/{parsed_url.netloc}/{path}"
|
|
80
|
+
if query:
|
|
81
|
+
redirect_path += f"?{query}"
|
|
82
|
+
return redirect_path
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
On the Odoo instance, go to *Settings* > *Technical* > *Storage* > *File Storage*.
|
|
2
|
+
|
|
3
|
+
When you create a new storage for s3 or modify an existing one, when you activate
|
|
4
|
+
the option "Use X-Sendfile To Serve Internal Url", 2 additional fields will appear:
|
|
5
|
+
|
|
6
|
+
- **S3 Uses Signed URL For X-Accel-Redirect**: If checked, the X-Accel-Redirect
|
|
7
|
+
path will be a signed URL, which is useful for S3 storages that require
|
|
8
|
+
signed URLs for access.
|
|
9
|
+
- **S3 Signed URL Expiration**: The expiration time for the signed URL in seconds.
|
|
10
|
+
This field is only relevant if the previous option is checked. By default,
|
|
11
|
+
it is set to 30 seconds but it could be less since the url generated into
|
|
12
|
+
the X-Accel-Redirect process is directly used by the web server to serve the file.
|
|
13
|
+
|
|
14
|
+
The value of these fields can also be set in the server environment variables using
|
|
15
|
+
the keys:
|
|
16
|
+
|
|
17
|
+
- *s3_uses_signed_url_for_x_sendfile*
|
|
18
|
+
- *s3_signed_url_expiration*
|
|
19
|
+
|
|
20
|
+
When the option "Use X-Sendfile To Serve Internal Url" is enabled, the system will
|
|
21
|
+
generate an X-Accel-Redirect header in the response to a request to get a file.
|
|
22
|
+
In the case of S3 storages, it will follow the format:
|
|
23
|
+
|
|
24
|
+
```text
|
|
25
|
+
X-Accel-Redirect: /fs_x_sendfile/{scheme}/{host}/{path with query if any}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Where:
|
|
29
|
+
|
|
30
|
+
- `{scheme}`: The URL scheme (http or https).
|
|
31
|
+
- `{host}`: The host of the S3 storage.
|
|
32
|
+
- `{path with query if any}`: The path to the file in the S3 storage,
|
|
33
|
+
including any query parameters. (Query parameters are set when the
|
|
34
|
+
`s3_uses_signed_url_for_x_sendfile` option is enabled.)
|
|
35
|
+
|
|
36
|
+
In order to serve files using X-Accel-Redirect, you must ensure that your
|
|
37
|
+
web server is configured to handle these headers correctly. This typically
|
|
38
|
+
involves setting up a location block in your web server configuration that
|
|
39
|
+
matches the X-Accel-Redirect path and proxies the request to the S3 storage.
|
|
40
|
+
|
|
41
|
+
For example, if you are using Nginx, you would add a location block like this:
|
|
42
|
+
|
|
43
|
+
```nginx
|
|
44
|
+
|
|
45
|
+
location ~ ^/fs_x_sendfile/(.*?)/(.*?)/(.*) {
|
|
46
|
+
internal;
|
|
47
|
+
set $url_scheme $1;
|
|
48
|
+
set $url_host $2;
|
|
49
|
+
set $url_path $3;
|
|
50
|
+
set $url $url_scheme://$url_host/$url_path;
|
|
51
|
+
|
|
52
|
+
proxy_pass $url$is_args$args;
|
|
53
|
+
proxy_set_header Host $url_host;
|
|
54
|
+
proxy_ssl_server_name on;
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
Unlike the standard implementation of X-Accel-Redirect on non S3 storages,
|
|
61
|
+
the S3 implementation does not require a base URL to be set in the storage
|
|
62
|
+
configuration. The X-Accel-Redirect path is constructed directly from the
|
|
63
|
+
S3 storage's URL defined for the connection, the directory name as
|
|
64
|
+
bucket name, and the file path.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
This module extends the functionality of [fs_attachment](https://github.com/OCA/storage/tree/16.0/fs_attachment)
|
|
2
|
+
to better support Amazon S3 storage. It includes features such as:
|
|
3
|
+
|
|
4
|
+
- Special handling of X-Accel-Redirect headers for S3 storages.
|
|
5
|
+
- Options for using signed URLs in X-Accel-Redirect. (This is required to be able to serve files from a private S3 bucket
|
|
6
|
+
using X-Accel-Redirect without exposing the files publicly.)
|
|
7
|
+
- Enforcing the mimetype of files stored in S3.
|
|
Binary file
|