Dyanmically changing Django Storage?

111 views
Skip to first unread message

zweb

unread,
Jan 27, 2014, 3:07:20 PM1/27/14
to django...@googlegroups.com

I am planning to use django-storages. It uses django settings, as

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

I read it is bad practice to change django settings during runtime. I am not using Django's FileField.

During run time, based on file size and type,  I want to use a different storage backend. How to do it?

Javier Guerra Giraldez

unread,
Jan 27, 2014, 3:19:18 PM1/27/14
to django...@googlegroups.com
On Mon, Jan 27, 2014 at 3:07 PM, zweb <ashis...@gmail.com> wrote:
> During run time, based on file size and type, I want to use a different
> storage backend. How to do it?


write a storage backend proxy that picks which 'real' backend to use
for each file.

note that during upload, you have to start storing before knowing the
full size of the file.

--
Javier

Avraham Serour

unread,
Jan 28, 2014, 2:38:30 AM1/28/14
to django...@googlegroups.com
you can define the storage for each FileField when declaring your model, it will use the default unless you specify something else.
Does your use case have the same model using different storages?
I suggest you make different models, each using the storage you want, 
Lets say you have two models, S3File and LocalFile
when uploading the file you then decide if it is a S3File object or a LocalFile object



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFkDaoRxkzGb1z3uLt%2B6WzFoKpgq6F05c7xdH9cqqLMhfHof8w%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages