我正在使用DigitalOcean Spaces建立一个Wagtail网站。静态文件正在加载,但是当我尝试从管理员上载图像时,它无法将图像上载到Spaces的媒体文件夹中,显示错误。这是我的存储配置:
AWS_ACCESS_KEY_ID = config('SPACES_ACCESS_KEY')
AWS_SECRET_ACCESS_KEY = config('SPACES_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = 'BUCKET_NAME'
AWS_S3_ENDPOINT_URL = 'https://nyc3.digitaloceanspaces.com'
AWS_S3_OBJECT_PARAMETERS = {
'CacheControl': 'max-age=86400',
}
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'my_app/static'),
]
STATICFILES_LOCATION = 'spaces-folder/static'
STATICFILES_STORAGE = 'custom_storages.StaticStorage'
MEDIAFILES_LOCATION = 'spaces-folder/media'
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
我还使用了custom_storages.py文件和以下两个类,以在this tutorial之后的同一Spaces存储桶中使用静态文件和媒体文件:
# custom_storages.py
from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage
class StaticStorage(S3Boto3Storage):
location = settings.STATICFILES_LOCATION
class MediaStorage(S3Boto3Storage):
location = settings.MEDIAFILES_LOCATION