Wednesday, June 17, 2015

[Django] Using cloud storage services as default storage backend

To use cloud storage services as default storage backend in Django – or actullay in Python, Apache's Libcloud wrapper can be a nice solution. Because it supports more than 30 providers, and has a huge community.

django-storages-redux app provides storage backends to use in Django. Good news, also supports Apache Libcloud. So you can use more than 30 cloud providers with Django. To install the app execute this:
$ pip install django-storages-redux
Also you must install Apache Libcloud:
$ pip install apache-libcloud
And enable from settings.py by adding following lines:
DEFAULT_FILE_STORAGE = 'storages.backends.apache_libcloud.LibCloudStorage'
DEFAULT_LIBCLOUD_PROVIDER = 'google_storage'
LIBCLOUD_PROVIDERS = {
 'google_storage': {
 'type': 'libcloud.storage.types.Provider.GOOGLE_STORAGE',
 'user': 'yourcloudstorageapikey:)',
 'key': 'yourcloudstorageapisecretkey:)',
 'bucket': 'default-bucket-name',
 }
}
 If you don't create bucket, you can create from shell:
$ ./manage.py shell

$ from storages.backends.apache_libcloud import LibCloudStorage
$ LibCloudStorage('google_storage').driver.create_container('default-bucket-name')

No comments:

Post a Comment