Rewrite update function consisting of move + create

This commit is contained in:
Tobias Eidelpes 2021-01-08 19:10:23 +01:00
parent e50e027ea9
commit 8c64333e27

View File

@ -170,7 +170,6 @@ class ImageEndpoint:
@staticmethod
@api_view(['PUT'])
def image_api_update(request, identifier):
logger.debug('Image UPDATE single call: {}'.format(request))
# get metadata from MongoDB
@ -190,8 +189,11 @@ class ImageEndpoint:
MongoDBService.updateSingle(identifier, decoded_image)
for service in ImageEndpoint.storageServiceList:
if not service.update_file(filename, decoded_image):
print("Could not save image to " + service.name)
orig_new_name = identifier + '_' + payload['metadata']['version'] + '.jpg'
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)
return JsonResponse({'id': identifier, 'filename': filename},
safe=False)