#3 add delete function
This commit is contained in:
parent
2e3e9f9fad
commit
8a50493b18
@ -32,7 +32,7 @@ class MinioService:
|
||||
if r.status_code == 200:
|
||||
print("Successfully uploaded a file!")
|
||||
else:
|
||||
print("Something went wrong")
|
||||
print("Something went wrong while creating")
|
||||
except:
|
||||
return False
|
||||
return True
|
||||
@ -53,3 +53,21 @@ class MinioService:
|
||||
except:
|
||||
print("Error downloading file from minio")
|
||||
return file_bytes
|
||||
|
||||
@staticmethod
|
||||
def delete_file(filename: str) -> bool:
|
||||
"""Delete an file from the dropbox storage.
|
||||
|
||||
:param filename: filename of the file
|
||||
:return: Whether file was successfully deleted
|
||||
"""
|
||||
try:
|
||||
url = settings.AWS_HOST + filename
|
||||
r = requests.delete(url)
|
||||
if r.status_code == 204:
|
||||
print("Successfully deleted a file!")
|
||||
else:
|
||||
print("Something went wrong while deleting")
|
||||
except:
|
||||
return False
|
||||
return True
|
||||
@ -113,6 +113,7 @@ class ImageEndpoint:
|
||||
|
||||
# get metadata from MongoDB
|
||||
metadata = MongoDBService.getSingle(identifier)
|
||||
|
||||
if not metadata:
|
||||
return JsonResponse({'Result': 'Error - could not find any metadata in mongoDB.',
|
||||
'id': identifier}, status=404, safe=False)
|
||||
@ -120,10 +121,15 @@ class ImageEndpoint:
|
||||
resp = MongoDBService.deleteSingle(identifier)
|
||||
print(resp)
|
||||
|
||||
|
||||
if not DropboxService.delete_file(metadata['filename']):
|
||||
print('Error deleting file in dropbox')
|
||||
result_bool = False
|
||||
|
||||
if not MinioService.delete_file(metadata['filename']):
|
||||
print('Error deleting file in minio')
|
||||
result_bool = False
|
||||
|
||||
return JsonResponse({'Result': result_bool}, safe=False)
|
||||
|
||||
@staticmethod
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user