Skip to content

Commit

Permalink
Dropbox: add configurable timeout and improve docs (#747)
Browse files Browse the repository at this point in the history
* Dropbox: add configurable timeout and improve docs

* Fix Flake8
  • Loading branch information
jschneier committed Sep 8, 2019
1 parent 3ffa081 commit 58c0fad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
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

0 comments on commit 58c0fad

Please sign in to comment.