5

I am using django-storages to serve media files on Dropbox. But I cannot get it working (media files are still stored in local server).

I've installed dropbox and django-storages, and created an app with permission type:app folder, then added related settings.

Here's my settings:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

DEBUG = False

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_filters',
    'website',
    'storages',
)

# for dropbox
DEFAULT_FILE_STORAGE = 'storages.backends.dropbox.DropBoxStorage'
DROPBOX_OAUTH2_TOKEN = 'my_generated_token_from_dropbox'
DROPBOX_ROOT_PATH = 'media'


MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

To be able to upload the media files to Dropbox (and reading them) what has to be changed in the settings code?

2
  • Can you clarify But I cannot get it working ? Commented Apr 8, 2018 at 8:40
  • cant get media files to store on the dropbox, they are still stored on the local server Commented Apr 8, 2018 at 9:28

1 Answer 1

2

Ok, found the problem! The settings are correct, the problem was that for some reason I was using a custom storage for my FileField! All I had to do was removing the storage=...:

file = models.FileField(upload_to=some_path, storage=CustomStorage())

to

file = models.FileField(upload_to=some_path)
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, I am having the same problem with this and stuck here for almost two days. can you share how you have solved this problem? My error is like this stone.backends.python_rsrc.stone_validators.ValidationError: 'D:/users/01926656698/01926656698.jpg' did not match pattern '(/(.|[\r\n])*|id:.*)|(rev:[0-9a-f]{9,})|(ns:[0-9]+(/.*)?)'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.