@@ -11,28 +11,31 @@ def __init__(self, *args, **kwargs):
11
11
self .local_storage = get_storage_class (
12
12
'compressor.storage.CompressorFileStorage' )()
13
13
14
- # Fix for "ValueError: seek of closed file" problem with boto3
15
- # https://github.com/jschneier/django-storages/issues/382 #issuecomment-377174808
16
- def _save_content (self , obj , content , parameters ):
14
+ # https://github.com/jschneier/django-storages/issues/382
15
+ # #issuecomment-592876060
16
+ def _save (self , name , content ):
17
17
"""
18
- We create a clone of the content file as when this is passed to boto3 it wrongly closes
19
- the file upon upload where as the storage backend expects it to still be open
18
+ We create a clone of the content file as when this is passed
19
+ to boto3 it wrongly closes the file upon upload where as the
20
+ storage backend expects it to still be open
20
21
"""
21
22
# Seek our content back to the start
22
23
content .seek (0 , os .SEEK_SET )
23
24
24
- # Create a temporary file that will write to disk after a specified size
25
- content_autoclose = SpooledTemporaryFile ()
25
+ # Create a temporary file that will write to disk after a
26
+ # specified size. This file will be automatically deleted when
27
+ # closed by boto3 or after exiting the `with` statement if the
28
+ # boto3 is fixed
29
+ with SpooledTemporaryFile () as content_autoclose :
26
30
27
- # Write our original content into our copy that will be closed by boto3
28
- content_autoclose .write (content .read ())
31
+ # Write our original content into our copy that will be
32
+ # closed by boto3
33
+ content_autoclose .write (content .read ())
29
34
30
- # Upload the object which will auto close the content_autoclose instance
31
- super (CachedS3BotoStorage , self )._save_content (obj , content_autoclose , parameters )
32
-
33
- # Cleanup if this is fixed upstream our duplicate should always close
34
- if not content_autoclose .closed :
35
- content_autoclose .close ()
35
+ # Upload the object which will auto close the
36
+ # content_autoclose instance
37
+ return super (CachedS3BotoStorage , self )._save (
38
+ name , content_autoclose )
36
39
37
40
def save (self , name , content ):
38
41
name = super (CachedS3BotoStorage , self ).save (name , content )
0 commit comments