Custom Storage For UpStorage.
Project description
django-upstorage-backend
This is a custom django storage backend for UpStorage
Installation
- Install Library Using
pip
>> pip install django-upstorage-backend
Starting Guide
- Set The Custom Storage Backend. Now Open settings.py of your project.
DEFAULT_FILE_STORAGE = 'django-upstorage-backend.storages.backends.U3Storage'
- Set some required KEYS to
settings.py
AUTH_TOKEN = 'auth token from your account'
API_KEY = 'api key of your project'
USERNAME = 'username of your account'
PROJECT_NAME = 'Created Project name'
Thats it, We are all done. Now all of your files will be handeled by the custom UpStorage's Backend Storage.
Advanced Guide
-
You don't need to set 'upload_to' in model Fields (Defaultly it files will be saved on the root of your project.)
-
File Link Will Be Stored On Your Model As Expected.You Can call them as you do usally.
-
You Can also set 'upload_to='specific/folder' in your model like:
Class TestModel(model.Model): image = models.ImageField(upload_to='to/my/folder') # this will save the file to that folder.if there's no folder it will create it.
-
If you want to delete the image from the UpStorage Bucket when you delete it from django, you have to do it a bit differently.Lemme show you
Class TestModel(model.Model): image = models.ImageField() # To delete the image you have to delete that by writing: obj = TestModel.objects.get(id=pk) obj.image.delete() # You can't directly delete it like this: obj.delete() # this won't delete the file from UpStorage # You have to delete the file field first to delete it.
To make it simple you can override
delete
Method on your ModelClass TestModel(model.Model): image = models.ImageField() def delete(self): self.image.delete() super(TestModel, self).delete()
Project details
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
Hashes for django-upstorage-backend-1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d8b4e2fa2660afcd1ef4b4cbdc515592e196720d2c9f5e8eb0dbde286548881 |
|
MD5 | dbd3fc1af478a647e467b640686a1325 |
|
BLAKE2b-256 | bd16a6a23703f41573ad047fa4cbbe7f35b0ce25fd16fe7ad8541b4d5b1f3079 |
Hashes for django_upstorage_backend-1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47f4cd5618c3d81b7e9a1ab47ea2a36acb4327e68e85754a38a603ec6372f396 |
|
MD5 | ccc08cad19cfab05b7461679b6c5c9b3 |
|
BLAKE2b-256 | 647fe89b044c737ff253ca1580fe0dbef20b08bd68d7f820fc1945c072fa38ea |