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

Dropbox: add configurable timeout and improve docs #747

Merged
merged 2 commits into from Sep 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 13 additions & 10 deletions docs/backends/dropbox.rst
@@ -1,14 +1,13 @@
DropBox
Dropbox
=======

A custom storage system for Django using Dropbox Storage backend.
A Django files storage using Dropbox as a backend via the official
`Dropbox SDK for Python`_. Currently only v2 of the API is supported.

Before you start configuration, you will need to install `Dropbox SDK for Python`_.
Before you start configuration, you will need to install the SDK
which can be done for you automatically by doing::


Install the package::

pip install dropbox
pip install django-storages[dropbox]

Settings
--------
Expand All @@ -18,10 +17,14 @@ To use DropBoxStorage set::
DEFAULT_FILE_STORAGE = 'storages.backends.dropbox.DropBoxStorage'

``DROPBOX_OAUTH2_TOKEN``
Your DropBox token, if you haven't follow this `guide step`_.
Your Dropbox token. You can obtain one by following the instructions in the `tutorial`_.

``DROPBOX_ROOT_PATH``
``DROPBOX_ROOT_PATH`` (optional)
Allow to jail your storage to a defined directory.

.. _`guide step`: https://www.dropbox.com/developers/documentation/python#tutorial
``DROPBOX_TIMEOUT`` (optional)
Timeout in seconds for making requests to the API. If ``None``, the client will wait forever.
The default is ``100`` seconds which is the current default in the official SDK.

.. _`tutorial`: https://www.dropbox.com/developers/documentation/python#tutorial
.. _`Dropbox SDK for Python`: https://www.dropbox.com/developers/documentation/python#tutorial
12 changes: 8 additions & 4 deletions storages/backends/dropbox.py
Expand Up @@ -25,6 +25,8 @@

from storages.utils import setting

_DEFAULT_TIMEOUT = 100


class DropBoxStorageException(Exception):
pass
Expand Down Expand Up @@ -67,13 +69,15 @@ class DropBoxStorage(Storage):

CHUNK_SIZE = 4 * 1024 * 1024

def __init__(self, oauth2_access_token=None, root_path=None):
def __init__(self, oauth2_access_token=None, root_path=None, timeout=None):
oauth2_access_token = oauth2_access_token or setting('DROPBOX_OAUTH2_TOKEN')
self.root_path = root_path or setting('DROPBOX_ROOT_PATH', '/')
if oauth2_access_token is None:
raise ImproperlyConfigured("You must configure a token auth at"
raise ImproperlyConfigured("You must configure an auth token at"
"'settings.DROPBOX_OAUTH2_TOKEN'.")
self.client = Dropbox(oauth2_access_token)

self.root_path = root_path or setting('DROPBOX_ROOT_PATH', '/')
timeout = timeout or setting('DROPBOX_TIMEOUT', _DEFAULT_TIMEOUT)
self.client = Dropbox(oauth2_access_token, timeout=timeout)

def _full_path(self, name):
if name == '/':
Expand Down