浏览代码

Need custom storage to have two different paths

Colin Powell 2 年之前
父节点
当前提交
2c946c1071
共有 2 个文件被更改,包括 16 次插入2 次删除
  1. 2 2
      vrobbler/settings.py
  2. 14 0
      vrobbler/storages.py

+ 2 - 2
vrobbler/settings.py

@@ -257,8 +257,8 @@ if os.getenv("VROBBLER_USE_S3", "False").lower() in TRUTHY:
     location = "/".join([AWS_S3_ENDPOINT_URL, AWS_STORAGE_BUCKET_NAME])
     print(f"Storing media on S3 at {location}")
 
-    DEFAULT_FILE_storage = "storages.backends.s3boto3.S3Boto3Storage"
-    STATICFILES_STORAGE = "storages.backends.s3boto3.S3StaticStorage"
+    DEFAULT_FILE_storage = "vrobbler.storages.MediaStorage"
+    STATICFILES_STORAGE = "vrobbler.storages.StaticStorage"
     STATIC_URL = location + "/static/"
     MEDIA_URL = location + "/media/"
 

+ 14 - 0
vrobbler/storages.py

@@ -0,0 +1,14 @@
+import os
+from storages.backends.s3boto3 import S3Boto3Storage
+
+AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STORAGE_BUCKET_NAME", "")
+
+
+class MediaStorage(S3Boto3Storage):
+    bucket_name = AWS_STORAGE_BUCKET_NAME
+    location = "media"
+
+
+class StaticStorage(S3Boto3Storage):
+    bucket_name = AWS_STORAGE_BUCKET_NAME
+    location = "static"