Skip to content

Use new STORAGES setting from Django 4.2+ #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ pip install django-minio-storage

Add `minio_storage` to `INSTALLED_APPS` in your project settings.

The last step is setting `DEFAULT_FILE_STORAGE` to
`"minio_storage.storage.MinioMediaStorage"`, and `STATICFILES_STORAGE` to
`"minio_storage.storage.MinioStaticStorage"`.
The last step is setting `STORAGES['default']['BACKEND']` to
`'minio_storage.storage.MinioMediaStorage'`, and `STORAGES['staticfiles']['BACKEND']` to
`'minio_storage.storage.MinioStaticStorage'`.

## Django settings Configuration

Expand All @@ -18,7 +18,7 @@ The following settings are available:
`minio.example.org:9000` (note that there is no scheme)).

- `MINIO_STORAGE_ACCESS_KEY` and `MINIO_STORAGE_SECRET_KEY` (mandatory)

- `MINIO_STORAGE_REGION`: Allows you to specify the region. By setting this
configuration option, an additional HTTP request to Minio for region checking
can be prevented, resulting in improved performance and reduced latency for
Expand All @@ -34,18 +34,18 @@ The following settings are available:
- `MINIO_STORAGE_AUTO_CREATE_MEDIA_BUCKET`: whether to create the bucket if it
does not already exist (default: `False`)

- `MINIO_STORAGE_ASSUME_MEDIA_BUCKET_EXISTS`: whether to ignore media bucket
creation and policy.
- `MINIO_STORAGE_ASSUME_MEDIA_BUCKET_EXISTS`: whether to ignore media bucket
creation and policy.
(default: `False`)

- `MINIO_STORAGE_AUTO_CREATE_MEDIA_POLICY`: sets the buckets public policy
right after it's been created by `MINIO_STORAGE_AUTO_CREATE_MEDIA_BUCKET`.
Valid values are: `GET_ONLY`, `READ_ONLY`, `WRITE_ONLY`, `READ_WRITE` and
`NONE`. (default: `GET_ONLY`)

- `MINIO_STORAGE_MEDIA_OBJECT_METADATA`: set default additional metadata for
every object persisted during save operations. The value is a dict with
string keys and values, example: `{"Cache-Control": "max-age=1000"}`.
string keys and values, example: `{'Cache-Control': 'max-age=1000'}`.
(default: `None`)

- `MINIO_STORAGE_STATIC_BUCKET_NAME`: the bucket that will act as `STATIC`
Expand All @@ -55,18 +55,18 @@ The following settings are available:
does not already exist (default: `False`)


- `MINIO_STORAGE_ASSUME_STATIC_BUCKET_EXISTS`: whether to ignore the static bucket
creation and policy.
- `MINIO_STORAGE_ASSUME_STATIC_BUCKET_EXISTS`: whether to ignore the static bucket
creation and policy.
(default: `False`)

- `MINIO_STORAGE_AUTO_CREATE_STATIC_POLICY`: sets the buckets public policy
right after it's been created by `MINIO_STORAGE_AUTO_CREATE_STATIC_BUCKET`.
Valid values are: `GET_ONLY`, `READ_ONLY`, `WRITE_ONLY`, `READ_WRITE` and
`NONE`. (default: `GET_ONLY`)

- `MINIO_STORAGE_STATIC_OBJECT_METADATA`: set default additional metadata for
every object persisted during save operations. The value is a dict with
string keys and values, example: `{"Cache-Control": "max-age=1000"}`.
string keys and values, example: `{'Cache-Control': 'max-age=1000'}`.
(default: `None`)

- `MINIO_STORAGE_MEDIA_URL`: the base URL for generating urls to objects from
Expand Down Expand Up @@ -110,13 +110,19 @@ The following settings are available:
STATIC_URL = '/static/'
STATIC_ROOT = './static_files/'

DEFAULT_FILE_STORAGE = "minio_storage.storage.MinioMediaStorage"
STATICFILES_STORAGE = "minio_storage.storage.MinioStaticStorage"
STORAGES = {
'default': {
'BACKEND': 'minio_storage.storage.MinioMediaStorage',
},
'staticfiles': {
'BACKEND': 'minio_storage.storage.MinioStaticStorage',
},
}
MINIO_STORAGE_ENDPOINT = 'minio:9000'
MINIO_STORAGE_ACCESS_KEY = 'KBP6WXGPS387090EZMG8'
MINIO_STORAGE_SECRET_KEY = 'DRjFXylyfMqn2zilAr33xORhaYz5r9e8r37XPz3A'
MINIO_STORAGE_USE_HTTPS = False
MINIO_STORAGE_MEDIA_OBJECT_METADATA = {"Cache-Control": "max-age=1000"}
MINIO_STORAGE_MEDIA_OBJECT_METADATA = {'Cache-Control': 'max-age=1000'}
MINIO_STORAGE_MEDIA_BUCKET_NAME = 'local-media'
MINIO_STORAGE_MEDIA_BACKUP_BUCKET = 'Recycle Bin'
MINIO_STORAGE_MEDIA_BACKUP_FORMAT = '%c/'
Expand Down
13 changes: 8 additions & 5 deletions tests/django_minio_storage_tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@

ALLOWED_HOSTS = []


DEFAULT_STORAGE = "minio_storage.storage.MinioMediaStorage"
STATICFILES_STORAGE = "minio_storage.storage.MinioStaticStorage"
STORAGES = {
"default": {
"BACKEND": "minio_storage.storage.MinioMediaStorage",
},
"staticfiles": {
"BACKEND": "minio_storage.storage.MinioStaticStorage",
},
}

MINIO_STORAGE_ENDPOINT = os.getenv("MINIO_STORAGE_ENDPOINT", "minio:9000")
MINIO_STORAGE_ACCESS_KEY = os.environ["MINIO_STORAGE_ACCESS_KEY"]
Expand Down Expand Up @@ -130,8 +135,6 @@

USE_I18N = True

USE_L10N = True

USE_TZ = True


Expand Down
2 changes: 1 addition & 1 deletion tests/test_app/tests/custom_storage_class_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@deconstructible
class PrivateStorage(MinioStorage):
"""The PrivateStorage MinioStorage subclass can be used directly, as a storage in
settings.DEFAULT_FILE_STORAGE or after instantiated used individually on any django
settings.STORAGES or after instantiated used individually on any django
FileField:

from django.db import models
Expand Down