Skip to main content

Custom Storage For UpStorage.

Project description

django-upstorage-backend

This is a custom django storage backend for UpStorage

Installation

  1. Install Library Using pip
>> pip install django-upstorage-backend

Starting Guide

  1. Set The Custom Storage Backend. Now Open settings.py of your project.
DEFAULT_FILE_STORAGE = 'django-upstorage-backend.storages.backends.U3Storage'
  1. 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 Model

    Class 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

django-upstorage-backend-0.9.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

django_upstorage_backend-0.9-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file django-upstorage-backend-0.9.tar.gz.

File metadata

  • Download URL: django-upstorage-backend-0.9.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for django-upstorage-backend-0.9.tar.gz
Algorithm Hash digest
SHA256 8fab3d0d7c6d8e051dc0b39930b3dd4fec7c3e754aff463af23ef8e3adaff3af
MD5 a785a579bdbc334dd8a74db268341c6f
BLAKE2b-256 046f52b4049bf4b925a30a5e8b3fd37ff9c9a06c1ae9b8742413778da9261237

See more details on using hashes here.

File details

Details for the file django_upstorage_backend-0.9-py3-none-any.whl.

File metadata

  • Download URL: django_upstorage_backend-0.9-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for django_upstorage_backend-0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 7b22bf8dc7f5bb9dddf0a2be4c3875248b395b838f54a4f74c9734ab4c4b5223
MD5 f5496d3962f68bbedd60771d5d50ebe4
BLAKE2b-256 cc625caab0a986ab2aeb052bd72599ca18b4bca494cc404fb927c819353cd495

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page