Django GridFS Storage Engine
Project description
django-gridfs-storage
Simple django GridFS storage engine
Usage:
- Install
django_gridfs_storage
:pip install django_gridfs_storage
- Into settings.py file of your project, add
gridfs_storage
toINSTALLED_APPS
:INSTALLED_APPS = [ ..., 'gridfs_storage', ]
- add the following variables to your settings:
# defaults to default local mongodb server DEFAULT_GRIDFS_URL = 'mongodb://127.0.0.1:27017' # if set to None, it will refuse to serve files and raise an Exception DEFAULT_GRIDFS_SERVE_URL = None DEFAULT_COLLECTION = 'storage'
- To serve files through django (not recommended) you can use this in urls.py:
urlpatterns = [ path('admin/', admin.site.urls), ..., path('media/', include('gridfs_storage.urls')), ]
and set the
DEFAULT_GRIDFS_SERVE_URL
to the prefix you specified in the path. in this case its/media/
- If you wish to use it on all
FileField
andImageField
set it as the default Storage:DEFAULT_FILE_STORAGE = 'gridfs_storage.storages.GridFSStorage'
- If you wish to use on individual field bases set it as the field storage:
from django.db import models from gridfs_storage.storages import GridFSStorage class SampleModel(models.Model): attachment = models.FileField(storage=GridFSStorage()) first_pic = models.ImageField(storage=GridFSStorage(location='sample/images')) # To store in a different collection than "storage" another_pic = models.ImageField(storage=GridFSStorage(collection='image_storage')) # Serve through custom cdn connected to the same gridfs or similar, the limit is the sky :) served_outside = models.ImageField(storage=GridFSStorage(base_url='https://img.cdn/serve/'))
Requirements:
- Python 3.6 or higher.
- Django 2.2 or higher.
- MongoDB 3.4 or higher.
Known Issues
# TODO: location has a problem, fix it
# TODO: upload doens't work outside of admin
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django-gridfs-storage-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9cf0e9520ec46446233e96ea04fb63bb006d04a569e47bcfbde0e9250464dd8 |
|
MD5 | 11763c04e1d25db4d80e11cad7bb9b6f |
|
BLAKE2b-256 | ab8c2c65a6db28249a902a826fa22c1e10046f0f3932714db34132271168e93b |
Close
Hashes for django_gridfs_storage-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed5b47b727f82056aa92c923baf828d902cf199ca75624a925afcf79c7cc5c07 |
|
MD5 | 4e4a6b0dffbc20c25ce5b5993630417c |
|
BLAKE2b-256 | 2d3238ddf7786f50698aaf9ed8e8f1e13b460712a141d45daa496cf0a24e112e |