我有一个使用django-storages作为后端的应用程序设置。
我相信文件上传本身可以正常工作,因为我没有遇到任何错误。但是,当我尝试使用file.open()
通过我的模型检索文件时我收到以下错误:
botocore.exceptions.ClientError: An error occurred (400) when calling the HeadObject operation: Bad Request
当我不加密文件(删除AWS_S3_OBJECT_PARAMETERS中的3个项目)时,保存和检索都可以正常工作。
这是我的SETTINGS.py
的相关部分AWS_ACCESS_KEY_ID = 'MY KEY ID IS HERE'
AWS_SECRET_ACCESS_KEY = 'MY SECRET IS HERE'
AWS_STORAGE_BUCKET_NAME = 'tickets'
AWS_S3_ENDPOINT_URL = 'https://sfo2.digitaloceanspaces.com'
AWS_S3_FILE_OVERWRITE = False
AWS_S3_OBJECT_PARAMETERS = {
'CacheControl': 'max-age=86400',
}
AWS_S3_ENCRYPTION = True
AWS_S3_OBJECT_PARAMETERS = {
'CacheControl': 'max-age=86400',
"SSECustomerAlgorithm":'AES256',
"SSECustomerKey":'at1TMx82nEy7SoAK8jHYanMQDVZMSLayXaaUvTc6CP0=',
"SSECustomerKeyMD5":'LWkBoT3psNdTYez70TVHUQ==',
}
AWS_S3_REGION_NAME = 'sfo2'
AWS_LOCATION = ''
AWS_DEFAULT_ACL = None
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'sendtickets/static'),
]
STATIC_URL = 'https://%s/%s/' % (AWS_S3_ENDPOINT_URL, AWS_LOCATION)
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'