Use delete + create instead of copy

This commit is contained in:
Tobias Eidelpes 2021-01-09 17:29:27 +01:00
parent 9744bdcf3b
commit 89ee1fa408

View File

@ -45,7 +45,7 @@ class MinioService(StorageServiceInterface):
return True
@staticmethod
def move_file(identifier_from: str, identifier_to: str) -> bool:
def move_file(identifier_from: str, identifier_to: str, file: bytes) -> bool:
"""Move/Rename a file on the S3 storage.
Consists of a PUT method (copying the object) and a delete method.
@ -56,15 +56,17 @@ class MinioService(StorageServiceInterface):
print("MinioService: Trying to move/rename file from {} to {}".format(identifier_from, identifier_to))
filename_from = identifier_from + '.jpg'
filename_to = identifier_to + '.jpg'
filename_to = identifier_to
url = settings.AWS_HOST + filename_to
headers = {'x-amz-copy-source': filename_from}
r = requests.put(url, headers=headers)
if r.status_code == 200:
print("Successfully moved/renamed the file {}!".format(filename_from))
else:
print("Something went wrong while moving/renaming the file {}".format(filename_from))
if not MinioService.delete_file(filename_from):
print("MinioService: Updating (delete) file {} failed".format(filename_from))
return False
if not MinioService.create_file(filename_to, file):
print("MinioService: Updating (create) file {} failed".format(filename_to))
return False
return True
@staticmethod
def read_file(filename: str) -> bytes: