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