Comments (3)
I referred to this issue to make the DRFObjectDownloadView
#24
from django-private-storage.
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.
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)
- Google cloud storage and others
- DjangoServer does not respect Content-Type
- How to retrieve files by object id? HOT 3
- adjust to django-storages 1.10.1 HOT 3
- Serve files that weren't uploaded via Django Admin/API HOT 2
- RemovedInDjango40Warning for ugettext_lazy import HOT 1
- Howto avoid traceback in case of PermissionDenied in custom can_access_file? HOT 1
- UnicodeEncodeError when uploading non-ascii filenames HOT 3
- UUID as a primary key HOT 1
- Reverse for 'send_private_file' not found. Django 4.0 HOT 1
- SuspiciousFileOperation
- How create custom permission ?
- Custom private storages with nginx
- FileNotFoundError if the file associated with a model instance has been removed, and delete() is called on a ModelForm for that instance. HOT 1
- django 4.1 compatibility HOT 5
- Make it to html
- https is not served when using drf.
- Checks fail in Actions CI Testing
- An error occurred (403)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-private-storage.