Skip to content

bodja/django-gcs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django Google Cloud Storage

Based on Google Cloud Storage JSON API.

Written using Google Cloud Python Client library.

Quick start

$ pip install django-gcs

Update settings.py

DJANGO_GCS = {
    'bucket': 'bucket-name',
    'http': get_http_credentials
}

Settings

DJANGO_GCS = {
    'bucket': None,
    'project': '',
    'credentials': None,
    'http': None,
    'cache_control': ['no-cache']
}
  • bucket name of the bucket on google cloud storage.
  • project google project name (not required).
  • credentials oauth2 credentials
  • http httplib2.Http instance or callable that returns httplib2.Http instance
  • cache_control is a list of strings. By default ['no-cache']

Note: One of credentials or http should be provided for authentication.

Usage

Set storage globally:

DEFAULT_FILE_STORAGE = 'django_gcs.GoogleCloudStorage'

Or per model:

from django_gcs import GoogleCloudStorage

class FileModel(models.Model):
    file = models.ImageField(storage=GoogleCloudStorage(bucket='some-bucket'))

Example how to generate HTTP object to make request.

import pickle
import httplib2

def get_http_credentials():
    with open('google/oauth2/credentials/file', 'r') as f:
        credentials = pickle.load(f)
        http_credentials = credentials.authorize(httplib2.Http())
    return http_credentials

About

Django google cloud storage backend

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages