Coder Social home page Coder Social logo

Comments (3)

aryaniyaps avatar aryaniyaps commented on August 23, 2024

I referred to this issue to make the DRFObjectDownloadView #24

from django-private-storage.

aryaniyaps avatar aryaniyaps commented on August 23, 2024

this is my storage class

import hashlib
import os
import uuid

from django.conf import settings
from django.core.files.storage import FileSystemStorage


class DefaultStorage(FileSystemStorage):
    def __init__(self, *args, **kwargs):
        super(DefaultStorage, self).__init__(*args, **kwargs)

    def get_available_name(self, name, max_length=None):
        # we return a hash of the
        # file given, in case we miss out, django calls
        # the get_alternative_name method
        dir_name, file_name = os.path.split(name)
        file_root, file_ext = os.path.splitext(file_name)

        file_root = hashlib.md5(file_root.encode()).hexdigest()
        name = os.path.join(dir_name, file_root + file_ext)
        return super(DefaultStorage, self).get_available_name(name, max_length)

    def get_alternative_name(self, file_root, file_ext):
        # we insert a random uuid hex string into the given
        # file name before returning the same back
        return '%s%s%s' % (file_root, uuid.uuid4().hex, file_ext)


# instantiate storage for private media access
# based on configured settings for django-private-storage
private_storage = DefaultStorage(location=settings.PRIVATE_STORAGE_ROOT, base_url=settings.PRIVATE_URL)

settings

# private-storage configuration
PRIVATE_URL = '/private/'
PRIVATE_STORAGE_ROOT = os.path.join(BASE_DIR, 'private/')
PRIVATE_STORAGE_SERVER = 'apache'

am I doing anything wrong here?

from django-private-storage.

aryaniyaps avatar aryaniyaps commented on August 23, 2024

the culprit was the PRIVATE_STORAGE_SERVER attribute in my settings. I had to remove it during development.

from django-private-storage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.