From d500518d8fd585d1e7404bb3ab6731ad027ed437 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Mon, 18 Jan 2021 17:26:24 +0100 Subject: [PATCH] Fix bug where old image was not saved on AWS --- middleware/app_be/services/dropboxservice.py | 2 +- middleware/app_be/services/minioservice.py | 4 +++- middleware/app_be/views/rest_api.py | 5 +---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/middleware/app_be/services/dropboxservice.py b/middleware/app_be/services/dropboxservice.py index 7dd31c8..3f61667 100644 --- a/middleware/app_be/services/dropboxservice.py +++ b/middleware/app_be/services/dropboxservice.py @@ -70,7 +70,7 @@ class DropboxService(StorageServiceInterface): return file_bytes @staticmethod - def move_file(identifier_from: str, identifier_to: str, file: bytes = None) -> bool: + def move_file(identifier_from: str, identifier_to: str) -> bool: """Move/Rename a file on the dropbox storage. :param identifier_from: Location of the file to be moved diff --git a/middleware/app_be/services/minioservice.py b/middleware/app_be/services/minioservice.py index b7afc20..3b593e7 100644 --- a/middleware/app_be/services/minioservice.py +++ b/middleware/app_be/services/minioservice.py @@ -66,7 +66,7 @@ class MinioService(StorageServiceInterface): return True @staticmethod - def move_file(identifier_from: str, identifier_to: str, file: bytes) -> bool: + def move_file(identifier_from: str, identifier_to: str) -> bool: """Move/Rename a file on the S3 storage. Consists of a PUT method (copying the object) and a delete method. @@ -79,6 +79,8 @@ class MinioService(StorageServiceInterface): filename_from = identifier_from + '.jpg' filename_to = identifier_to + file = MinioService.read_file(filename_from) + if not MinioService.delete_file(filename_from): print("MinioService: Updating (delete) file {} failed".format(filename_from)) return False diff --git a/middleware/app_be/views/rest_api.py b/middleware/app_be/views/rest_api.py index 6f7bdae..d9966d5 100644 --- a/middleware/app_be/views/rest_api.py +++ b/middleware/app_be/views/rest_api.py @@ -238,12 +238,9 @@ class ImageEndpoint: MongoDBService.updateSingle(identifier, decoded_image, metadata) - # TODO TOBIAS get old image for MinIO - old_bytes = None - for service in ImageEndpoint.storageServiceList: orig_new_name = identifier + '_' + str(metadata['version']) + '.jpg' - if not service.move_file(identifier, orig_new_name, old_bytes): + if not service.move_file(identifier, orig_new_name): print("Could not move file from {} to {}".format(identifier, orig_new_name)) if not service.create_file(filename, decoded_image): print("Could not save updated image to " + service.name)