From ca5cc4e8811a8244422fdfab61254b866b822eee Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sat, 7 Dec 2019 11:19:00 +0100 Subject: s3: Delete file if add_file raises an exception --- fbin/file_storage/s3.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'fbin') diff --git a/fbin/file_storage/s3.py b/fbin/file_storage/s3.py index 9e68186..a11488f 100644 --- a/fbin/file_storage/s3.py +++ b/fbin/file_storage/s3.py @@ -29,7 +29,11 @@ class Storage(BaseStorage): if not size: obj = self.client.ObjectSummary(self.app.config['S3_BUCKET'], key) size = obj.size - return self.add_file(file_hash, uploaded_file.filename, size, user, ip) + try: + return self.add_file(file_hash, uploaded_file.filename, size, user, ip) + except: + obj.delete() + raise def get_file(self, f, thumb=False): key = self.get_object_key(f, thumb=thumb) -- cgit v1.2.3