I have configured the django-storages
to point to OCI bucket. Below is the configuration:
AWS_S3_ACCESS_KEY_ID = env('AWS_BUCKET_KEY')
AWS_SECRET_ACCESS_KEY = env('AWS_BUCKET_SECRET')
AWS_BUCKET_NAMESPACE = env('AWS_BUCKET_NAMESPACE')
AWS_STORAGE_BUCKET_NAME = env('AWS_BUCKET_NAME')
AWS_S3_BUCKET_REGION = env('AWS_S3_BUCKET_REGION')
AWS_S3_ENDPOINT_URL = f'https://{AWS_BUCKET_NAMESPACE}.compat.objectstorage. {AWS_S3_BUCKET_REGION}.oraclecloud.com'
AWS_S3_OBJECT_PARAMETERS = {
'CacheControl': 'max-age=86400',
}
AWS_LOCATION = f'{AWS_S3_ENDPOINT_URL}/{AWS_STORAGE_BUCKET_NAME}'
AWS_DEFAULT_ACL = 'public-read'
STATICFILES_STORAGE = 'custom_storages.StaticStorage'
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
# Use AWS_S3_ENDPOINT_URL here if you haven't enabled the CDN and got a custom domain.
STATIC_URL = '{}/{}/'.format(AWS_LOCATION, 'static')
STATIC_ROOT = 'var/static/'
STATICFILES_DIRS = [
BASE_DIR / "static"
]
MEDIA_URL = '{}/{}/'.format(AWS_LOCATION, 'media')
MEDIA_ROOT = 'media/'
and this is the custom storage config
from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage
class StaticStorage(S3Boto3Storage):
bucket_name = settings.AWS_STORAGE_BUCKET_NAME
location = 'static'
class MediaStorage(S3Boto3Storage):
bucket_name = settings.AWS_STORAGE_BUCKET_NAME
location = 'media'
All my static files are being served and no issues, but the application doesn't recognize the style files at all.
Also when I try to upload a new file, it gives the following error:
botocore.exceptions.ClientError: An error occurred (SignatureDoesNotMatch) when calling the PutObject operation:
The secret key required to complete authentication could not be found. The region must be specified if this is not the home region for the tenancy.
What could be the issue?
------ UPDATE ------
for this issue:
Also when I try to upload a new file, it gives the following error:
botocore.exceptions.ClientError: An error occurred (SignatureDoesNotMatch) when calling the PutObject operation: The secret key required to complete authentication could not be found. The region must be specified if this is not the home region for the tenancy.
It was resolved by adding the keys in the custom storage class:
from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage
class StaticStorage(S3Boto3Storage):
access_key = settings.AWS_S3_ACCESS_KEY_ID
secret_key = settings.AWS_SECRET_ACCESS_KEY
bucket_name = settings.AWS_STORAGE_BUCKET_NAME
region_name = settings.AWS_S3_BUCKET_REGION
location = 'static'
class MediaStorage(S3Boto3Storage):
access_key = settings.AWS_S3_ACCESS_KEY_ID
secret_key = settings.AWS_SECRET_ACCESS_KEY
bucket_name = settings.AWS_STORAGE_BUCKET_NAME
region_name = settings.AWS_S3_BUCKET_REGION
location = 'media'
The issue of style not reflecting persists.
for this issue:
Also when I try to upload a new file, it gives the following error:
botocore.exceptions.ClientError: An error occurred (SignatureDoesNotMatch) when calling the PutObject operation: The secret key required to complete authentication could not be found. The region must be specified if this is not the home region for the tenancy.
It was resolved by adding the keys in the custom storage class:
from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage
class StaticStorage(S3Boto3Storage):
access_key = settings.AWS_S3_ACCESS_KEY_ID
secret_key = settings.AWS_SECRET_ACCESS_KEY
bucket_name = settings.AWS_STORAGE_BUCKET_NAME
region_name = settings.AWS_S3_BUCKET_REGION
location = 'static'
class MediaStorage(S3Boto3Storage):
access_key = settings.AWS_S3_ACCESS_KEY_ID
secret_key = settings.AWS_SECRET_ACCESS_KEY
bucket_name = settings.AWS_STORAGE_BUCKET_NAME
region_name = settings.AWS_S3_BUCKET_REGION
location = 'media'
The issue of the style not reflecting was due to files being stored as text file not css or js. changing the file type in the bucket resolved the issue.