Skip to content

Commit d7102dd

Browse files
author
aaron
committed
fix #104, prepend default_storage.location to upload_path then strip it back out before passing to S3Boto3Storage
1 parent c6addde commit d7102dd

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

s3file/forms.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ class S3FileInputMixin:
1414
"""FileInput that uses JavaScript to directly upload to Amazon S3."""
1515

1616
needs_multipart_form = False
17-
upload_path = getattr(
18-
settings, 'S3FILE_UPLOAD_PATH', pathlib.PurePosixPath('tmp', 's3file')
19-
)
17+
try:
18+
upload_path = pathlib.PurePosixPath(
19+
default_storage.location, getattr(settings, 'S3FILE_UPLOAD_PATH')
20+
)
21+
except AttributeError:
22+
upload_path = pathlib.PurePosixPath(default_storage.location, 'tmp', 's3file')
23+
2024
expires = settings.SESSION_COOKIE_AGE
2125

2226
@property

s3file/middleware.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __call__(self, request):
2323
def get_files_from_storage(paths):
2424
"""Return S3 file where the name does not include the path."""
2525
for path in paths:
26+
path = path.lstrip(default_storage.location + '/')
2627
try:
2728
f = default_storage.open(path)
2829
f.name = os.path.basename(path)

0 commit comments

Comments
 (0)