diff options
| author | aryan <aryan@Aryans-MacBook-Pro.local> | 2020-02-20 00:23:48 +0530 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-09-30 10:30:43 +0200 |
| commit | 11c4a4412b74bb1dfe52d706a58f230066821c33 (patch) | |
| tree | e97fad6c1f924d372f791e6637a435f439a1f146 /django/core/files/uploadhandler.py | |
| parent | 21b127bfbc8738705ecee97407161caae612d6b1 (diff) | |
Fixed #30422 -- Made TemporaryFileUploadHandler handle interrupted uploads.
This patch allows upload handlers to handle interrupted uploads.
Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'django/core/files/uploadhandler.py')
| -rw-r--r-- | django/core/files/uploadhandler.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/django/core/files/uploadhandler.py b/django/core/files/uploadhandler.py index 613983581c..ee6bb31fce 100644 --- a/django/core/files/uploadhandler.py +++ b/django/core/files/uploadhandler.py @@ -1,7 +1,7 @@ """ Base file upload handler classes, and the built-in concrete subclasses """ - +import os from io import BytesIO from django.conf import settings @@ -127,6 +127,13 @@ class FileUploadHandler: """ pass + def upload_interrupted(self): + """ + Signal that the upload was interrupted. Subclasses should perform + cleanup that is necessary for this handler. + """ + pass + class TemporaryFileUploadHandler(FileUploadHandler): """ @@ -147,6 +154,15 @@ class TemporaryFileUploadHandler(FileUploadHandler): self.file.size = file_size return self.file + def upload_interrupted(self): + if hasattr(self, 'file'): + temp_location = self.file.temporary_file_path() + try: + self.file.close() + os.remove(temp_location) + except FileNotFoundError: + pass + class MemoryFileUploadHandler(FileUploadHandler): """ |
