File tree 2 files changed +10
-7
lines changed
2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change 1
1
import json
2
2
import logging
3
- import os
3
+ import pathlib
4
4
5
5
from s3file .storages import local_dev , storage
6
6
@@ -28,11 +28,10 @@ def __call__(self, request):
28
28
def get_files_from_storage (paths ):
29
29
"""Return S3 file where the name does not include the path."""
30
30
for path in paths :
31
- if storage .location :
32
- path = path .replace (os .path .dirname (storage .location ) + "/" , "" , 1 )
31
+ path = pathlib .PurePosixPath (path )
33
32
try :
34
- f = storage .open (path )
35
- f .name = os . path .basename ( path )
33
+ f = storage .open (path . relative_to ( storage . location ) )
34
+ f .name = path .name
36
35
yield f
37
- except OSError :
36
+ except ( OSError , ValueError ) :
38
37
logger .exception ("File not found: %s" , path )
Original file line number Diff line number Diff line change
1
+ import os
2
+
1
3
from django .core .files .base import ContentFile
2
4
from django .core .files .uploadedfile import SimpleUploadedFile
3
5
@@ -11,7 +13,9 @@ def test_get_files_from_storage(self):
11
13
name = storage .save (
12
14
"tmp/s3file/test_get_files_from_storage" , ContentFile (content )
13
15
)
14
- files = S3FileMiddleware .get_files_from_storage ([name ])
16
+ files = S3FileMiddleware .get_files_from_storage (
17
+ [os .path .join (storage .location , name )]
18
+ )
15
19
file = next (files )
16
20
assert file .read () == content
17
21
You can’t perform that action at this time.
0 commit comments