Added update (pre minio delete)

This commit is contained in:
Martin Schett
2020-12-06 19:36:30 +01:00
parent f313d18313
commit c440b66894
4 changed files with 79 additions and 1 deletions
+34
View File
@@ -142,6 +142,40 @@ class ImageEndpoint:
return JsonResponse({'Result': result_bool}, safe=False)
@staticmethod
@api_view(['PUT'])
def image_api_update(request, identifier):
logger.debug('Image UPDATE single call: {}'.format(request))
# get metadata from MongoDB
metadata = MongoDBService.getSingle(identifier)
if not metadata:
return JsonResponse({'Result': 'Error - Could not find image to be updated',
'id': identifier}, status=404, safe=False)
DropboxService.delete_file(metadata['filename'])
# MinioService.delete_file(metadata['filename'])
MongoDBService.deleteSingle(identifier)
payload = json.loads(request.body)
b64encoded_image = payload['image_data']
identifier = payload['id']
metadata = payload['metadata']
filename = payload['metadata']['filename']
decoded_image = WrapperService.unwrap_file(b64encoded_image)
MongoDBService.createSingle(metadata, identifier, decoded_image)
if not DropboxService.create_file(filename, decoded_image):
print("Could not save image to dropbox")
if not MinioService.create_file(filename, decoded_image):
print("Could not save image to minio")
return JsonResponse({'id': identifier, 'filename': filename},
safe=False)
class HealthEndpoint:
@staticmethod
@api_view(['GET'])