Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added temporary storage via settings flag #39

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
9 changes: 8 additions & 1 deletion chunked_upload/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ 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:
from chunked_upload.storages import TemporaryFileStorage
STORAGE = TemporaryFileStorage()
jerinpetergeorge marked this conversation as resolved.
Show resolved Hide resolved


# Boolean that defines if the ChunkedUpload model is abstract or not
Expand Down
7 changes: 7 additions & 0 deletions chunked_upload/storages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import tempfile

from django.core.files.storage import FileSystemStorage


class TemporaryFileStorage(FileSystemStorage):
location = tempfile.gettempdir()