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
+43
View File
@@ -42,6 +42,35 @@ def send_image(identifier, image_path, metadata_payload):
return True
def update_image(identifier, image_path, metadata_payload):
print("Updating image with identifier " + identifier)
if not os.path.isfile(image_path):
print("No image found at path " + image_path)
return False
file_encoded_b64 = None
with open(image_path, "rb") as file_to_send:
file_encoded_b64 = base64.b64encode(file_to_send.read())
if file_encoded_b64 is None:
print("Error reading file")
return False
file_payload = file_encoded_b64.decode('utf-8')
baseurl = "http://127.0.0.1:8000"
post_url = "/image/update/" + identifier
body = {
'id': identifier,
'metadata': metadata_payload,
'image_data': file_payload
}
try:
response = requests.put(baseurl + post_url, json=body)
print_response(response)
except os.error:
print("Error sending request")
return True
def get_image(identifier):
print("Getting image with identifier " + identifier)
@@ -190,6 +219,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
print("imagefolder <path> - selected new image folder")
print("show - opens image next in line in default os program")
print("trigger - next image in line is sent to backend")
print("update - next image in line is updated in backend")
print("fetch - gets the next image from database if exists")
print("fetchall - get all images")
print("delete - delets the next image from db if exists")
@@ -272,6 +302,19 @@ while (command.lower() not in ["exit", "quit", "end"]):
index = index + 1
print_cursor()
if command.lower() == "update":
if metadata is None:
print("No metadata loaded")
continue
if image_folder is None:
print("No image folder selected")
continue
meta_payload = metadata[index]
filename = meta_payload['filename']
update_image(filename[:-4], image_folder + os.path.sep + filename, meta_payload)
index = index + 1
print_cursor()
if command.lower() == "fetch":
if metadata is None:
print("No metadata loaded")