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 all 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
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -124,6 +124,7 @@ Add any of these variables into your project settings to override them.
* Content-Type for the response data.
* Default: ``'application/json'``


``CHUNKED_UPLOAD_MAX_BYTES``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -145,4 +146,4 @@ Add any of these variables into your project settings to override them.
Support
-------

If you find any bug or you want to propose a new feature, please use the `issues tracker <https://github.com/juliomalegria/django-chunked-upload/issues>`__. I'll be happy to help you! :-)
If you find any bug or you want to propose a new feature, please use the `issues tracker <https://github.com/juliomalegria/django-chunked-upload/issues>`__. I'll be happy to help you! :-)
8 changes: 6 additions & 2 deletions chunked_upload/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ def default_upload_to(instance, filename):
UPLOAD_TO = getattr(settings, 'CHUNKED_UPLOAD_TO', default_upload_to)

# Storage system


try:
# Use via settings defined storage (temporary storage is the fallback)
STORAGE = getattr(settings, 'CHUNKED_UPLOAD_STORAGE_CLASS', lambda: None)()
# Use temporary storage for chunks
if not STORAGE:
from chunked_upload.storages import TemporaryFileStorage
STORAGE = TemporaryFileStorage()

except TypeError:
STORAGE = import_string(getattr(settings, 'CHUNKED_UPLOAD_STORAGE_CLASS', lambda: None))()

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()