-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feito upload de arquivos publicos ou privados
close #17
- Loading branch information
Showing
8 changed files
with
161 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from django.db.models import Model | ||
from django_min_custom_user.models import MinAbstractUser | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from storages.backends.s3 import S3Storage | ||
|
||
|
||
class FileConfigurationError(Exception): | ||
pass | ||
|
||
|
||
class S3FileStorage(S3Storage): | ||
def url(self, name, parameters=None, expire=None, http_method=None): | ||
url = super().url(name, parameters, expire, http_method) | ||
if name.startswith('public'): | ||
url = url.split('?')[0] | ||
return url | ||
|
||
def get_object_parameters(self, name): | ||
parameters = super().get_object_parameters(name) | ||
self._validate(name) | ||
if self._startswith(name, 'public'): | ||
parameters['ACL'] = 'public-read' | ||
else: | ||
parameters['ACL'] = 'private' | ||
return parameters | ||
|
||
def _validate(self, name: str): | ||
if not (self._startswith(name, 'public') or self._startswith(name, 'private')): | ||
raise FileConfigurationError(f'property "upload_to" must start with "public" or "private" and it is {name}') | ||
|
||
def _startswith(self, name, prefix): | ||
return name.startswith(f'{self.location}/{prefix}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters