From 4bd119df17d36f120adb17fab37bf713851074f1 Mon Sep 17 00:00:00 2001 From: Ronny Vedrilla Date: Wed, 28 Mar 2018 10:54:55 +0200 Subject: [PATCH 1/6] Add variable to decide whether to use configurable storage backend or store chunks in OS temporary storage --- chunked_upload/settings.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/chunked_upload/settings.py b/chunked_upload/settings.py index 783e50e..205d37b 100644 --- a/chunked_upload/settings.py +++ b/chunked_upload/settings.py @@ -35,7 +35,15 @@ def default_upload_to(instance, filename): # Storage system -STORAGE = getattr(settings, 'CHUNKED_UPLOAD_STORAGE_CLASS', lambda: None)() +USE_TEMP_STORAGE = getattr(settings, 'CHUNKED_UPLOAD_USE_TEMP_STORAGE', False) +# Use django default or via settings defined storage +if not USE_TEMP_STORAGE: + STORAGE = getattr(settings, 'CHUNKED_UPLOAD_STORAGE_CLASS', lambda: None)() +# Use temporary storage for chunks +else: + import tempfile + from django.core.files.storage import FileSystemStorage + STORAGE = FileSystemStorage(location=tempfile.gettempdir()) # Boolean that defines if the ChunkedUpload model is abstract or not From 1bdc1a76b5bf10f1b5b97c64bb930777e7ed39fc Mon Sep 17 00:00:00 2001 From: Ronny Vedrilla Date: Wed, 28 Mar 2018 11:20:33 +0200 Subject: [PATCH 2/6] Add new var to Readme --- README.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.rst b/README.rst index cad9898..fc26b28 100644 --- a/README.rst +++ b/README.rst @@ -112,6 +112,12 @@ Add any of these variables into your project settings to override them. * Storage system (should be a class). * Default: ``None`` (use default storage system) +``CHUNKED_UPLOAD_USE_TEMP_STORAGE`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +* Activates temporary file storage. Useful for AWS S3. +* Default: ``False`` (use default storage system or ``CHUNKED_UPLOAD_STORAGE_CLASS``) + ``CHUNKED_UPLOAD_ABSTRACT_MODEL`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 141c47b6d6953b57afe3e3f88d19397a7902e589 Mon Sep 17 00:00:00 2001 From: Ronny Vedrilla Date: Thu, 29 Mar 2018 11:08:22 +0200 Subject: [PATCH 3/6] Fix with indirect call of storage location function --- chunked_upload/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chunked_upload/settings.py b/chunked_upload/settings.py index 205d37b..ab4699e 100644 --- a/chunked_upload/settings.py +++ b/chunked_upload/settings.py @@ -43,7 +43,7 @@ def default_upload_to(instance, filename): else: import tempfile from django.core.files.storage import FileSystemStorage - STORAGE = FileSystemStorage(location=tempfile.gettempdir()) + STORAGE = FileSystemStorage(location=tempfile.gettempdir) # Boolean that defines if the ChunkedUpload model is abstract or not From bdc962485076763d12bfad5469f31a18f8afc9c3 Mon Sep 17 00:00:00 2001 From: Ronny Vedrilla Date: Thu, 29 Mar 2018 12:39:48 +0200 Subject: [PATCH 4/6] Fixed storage for correct generated migrations --- chunked_upload/settings.py | 5 ++--- chunked_upload/storages.py | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 chunked_upload/storages.py diff --git a/chunked_upload/settings.py b/chunked_upload/settings.py index ab4699e..f06c854 100644 --- a/chunked_upload/settings.py +++ b/chunked_upload/settings.py @@ -41,9 +41,8 @@ def default_upload_to(instance, filename): STORAGE = getattr(settings, 'CHUNKED_UPLOAD_STORAGE_CLASS', lambda: None)() # Use temporary storage for chunks else: - import tempfile - from django.core.files.storage import FileSystemStorage - STORAGE = FileSystemStorage(location=tempfile.gettempdir) + from chunked_upload.storages import TemporaryFileStorage + STORAGE = TemporaryFileStorage() # Boolean that defines if the ChunkedUpload model is abstract or not diff --git a/chunked_upload/storages.py b/chunked_upload/storages.py new file mode 100644 index 0000000..267f4f1 --- /dev/null +++ b/chunked_upload/storages.py @@ -0,0 +1,7 @@ +import tempfile + +from django.core.files.storage import FileSystemStorage + + +class TemporaryFileStorage(FileSystemStorage): + location = tempfile.gettempdir() \ No newline at end of file From 8dae12aeff87daa6ee89ae369517599136dc5032 Mon Sep 17 00:00:00 2001 From: Ronny Vedrilla Date: Mon, 16 Dec 2019 14:24:09 +0100 Subject: [PATCH 5/6] Linting --- chunked_upload/storages.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chunked_upload/storages.py b/chunked_upload/storages.py index 267f4f1..e7c9ec0 100644 --- a/chunked_upload/storages.py +++ b/chunked_upload/storages.py @@ -4,4 +4,4 @@ class TemporaryFileStorage(FileSystemStorage): - location = tempfile.gettempdir() \ No newline at end of file + location = tempfile.gettempdir() From 11c1c91014d39f8c0627e9f92104059d1baaddd1 Mon Sep 17 00:00:00 2001 From: Ronny Vedrilla Date: Fri, 20 Dec 2019 14:49:54 +0100 Subject: [PATCH 6/6] Removed new settings var --- README.rst | 8 +------- chunked_upload/settings.py | 8 +++----- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/README.rst b/README.rst index 64680bf..675e00b 100644 --- a/README.rst +++ b/README.rst @@ -110,7 +110,7 @@ Add any of these variables into your project settings to override them. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Storage system (should be a class). -* Default: ``None`` (use default storage system) +* Default: ``TemporaryFileStorage`` ``CHUNKED_UPLOAD_ENCODER`` ~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -124,12 +124,6 @@ Add any of these variables into your project settings to override them. * Content-Type for the response data. * Default: ``'application/json'`` -``CHUNKED_UPLOAD_USE_TEMP_STORAGE`` -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -* Activates temporary file storage. Useful for AWS S3. -* Default: ``False`` (use default storage system or ``CHUNKED_UPLOAD_STORAGE_CLASS``) - ``CHUNKED_UPLOAD_MAX_BYTES`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/chunked_upload/settings.py b/chunked_upload/settings.py index a2968ab..38b6897 100644 --- a/chunked_upload/settings.py +++ b/chunked_upload/settings.py @@ -35,12 +35,10 @@ def default_upload_to(instance, filename): # Storage system try: - USE_TEMP_STORAGE = getattr(settings, 'CHUNKED_UPLOAD_USE_TEMP_STORAGE', False) - # Use django default or via settings defined storage - if not USE_TEMP_STORAGE: - STORAGE = getattr(settings, 'CHUNKED_UPLOAD_STORAGE_CLASS', lambda: None)() + # Use via settings defined storage (temporary storage is the fallback) + STORAGE = getattr(settings, 'CHUNKED_UPLOAD_STORAGE_CLASS', lambda: None)() # Use temporary storage for chunks - else: + if not STORAGE: from chunked_upload.storages import TemporaryFileStorage STORAGE = TemporaryFileStorage()