remove try catch, it is catched a step above to keep the exception information;

added additional parse try with:
-payload = request.data.dict()
-payload['metadata'] = json.loads(payload['metadata']);
update metadata on update;
prohibit . in filename;
This commit is contained in:
Marco Zeisler
2021-01-15 23:41:35 +01:00
parent a54fc5eb01
commit 95180bb8e7
2 changed files with 42 additions and 24 deletions
+7 -12
View File
@@ -60,20 +60,13 @@ class MongoDBService:
db = instance.AIC
col = db.metadata
try:
metadata['identifier'] = identifier
metadata['location'] = [metadata['longitude'], metadata['latitude']]
metadata['sha512'] = create_sha512(decoded_image)
col.insert_one(metadata)
except:
print("Could not insert Metadata")
return False
return True
metadata['identifier'] = identifier
metadata['location'] = [metadata['longitude'], metadata['latitude']]
metadata['sha512'] = create_sha512(decoded_image)
col.insert_one(metadata)
@staticmethod
def updateSingle(identifier, decoded_image) -> bool:
def updateSingle(identifier, decoded_image, meta=None) -> bool:
print("MongoDBService: Trying to update file with identifier " + identifier)
instance = MongoManager.getInstance()
db = instance.AIC
@@ -87,6 +80,8 @@ class MongoDBService:
identifier_changed = identifier + '_' + str(metadata_orig['version']) # Set identifier to include version
metadata_new['version'] = str(int(metadata_new['version']) + 1) # Increment version by one
metadata_new.update(meta)
print("MongoDBService: identifier_changed: ", identifier_changed)
col.update_one(old, {"$set": {"identifier": identifier_changed, "filename": identifier_changed + '.jpg'}})