File tree Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change 11import json
22import logging
3- import os
3+ import pathlib
44
55from s3file .storages import local_dev , storage
66
@@ -28,11 +28,10 @@ def __call__(self, request):
2828 def get_files_from_storage (paths ):
2929 """Return S3 file where the name does not include the path."""
3030 for path in paths :
31- if storage .location :
32- path = path .replace (os .path .dirname (storage .location ) + "/" , "" , 1 )
31+ path = pathlib .PurePosixPath (path )
3332 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
3635 yield f
37- except OSError :
36+ except ( OSError , ValueError ) :
3837 logger .exception ("File not found: %s" , path )
Original file line number Diff line number Diff line change 1+ import os
2+
13from django .core .files .base import ContentFile
24from django .core .files .uploadedfile import SimpleUploadedFile
35
@@ -11,7 +13,9 @@ def test_get_files_from_storage(self):
1113 name = storage .save (
1214 "tmp/s3file/test_get_files_from_storage" , ContentFile (content )
1315 )
14- files = S3FileMiddleware .get_files_from_storage ([name ])
16+ files = S3FileMiddleware .get_files_from_storage (
17+ [os .path .join (storage .location , name )]
18+ )
1519 file = next (files )
1620 assert file .read () == content
1721
You can’t perform that action at this time.
0 commit comments