add image sha512 hash to mongo on post;
This commit is contained in:
parent
d7e2bf651b
commit
19bb2c01fb
@ -1,5 +1,6 @@
|
||||
import pymongo
|
||||
|
||||
|
||||
class MongoManager:
|
||||
__instance = None
|
||||
|
||||
@ -17,6 +18,7 @@ class MongoManager:
|
||||
db = MongoManager.__instance.AIC
|
||||
coll = db.metadata
|
||||
db.coll["identifier"]
|
||||
db.coll["sha512"]
|
||||
db.coll["location"]
|
||||
coll.create_index("identifier",unique=True)
|
||||
coll.create_index("identifier", unique=True)
|
||||
coll.create_index([("location", pymongo.GEO2D)])
|
||||
@ -1,6 +1,6 @@
|
||||
import hashlib
|
||||
import logging
|
||||
import json
|
||||
import base64
|
||||
|
||||
from app_be.services.dropboxservice import DropboxService
|
||||
from app_be.services.wrapperservice import WrapperService
|
||||
@ -43,7 +43,6 @@ class ImageEndpoint:
|
||||
|
||||
return JsonResponse({'Result': 'success1'}, safe=False)
|
||||
|
||||
|
||||
@staticmethod
|
||||
@api_view(['GET'])
|
||||
def image_api_get_single(request, identifier):
|
||||
@ -68,7 +67,8 @@ class ImageEndpoint:
|
||||
dropbox_image_bytes = DropboxService.read_file(metadata['filename'])
|
||||
|
||||
if dropbox_image_bytes is None:
|
||||
return JsonResponse({'Result': 'Error - could not find image in dropbox.', 'id': identifier}, status=404, safe=False)
|
||||
return JsonResponse({'Result': 'Error - could not find image in dropbox.', 'id': identifier}, status=404,
|
||||
safe=False)
|
||||
|
||||
payload = {
|
||||
'id': identifier,
|
||||
@ -93,15 +93,20 @@ class ImageEndpoint:
|
||||
db = instance.AIC
|
||||
col = db.metadata
|
||||
|
||||
decoded_image = WrapperService.unwrap_file(b64encoded_image)
|
||||
h = hashlib.sha512()
|
||||
h.update(decoded_image)
|
||||
metadata['sha512'] = h.hexdigest()
|
||||
|
||||
try:
|
||||
metadata['identifier'] = identifier
|
||||
metadata['location'] = [metadata['longitude'],metadata['latitude']]
|
||||
metadata['location'] = [metadata['longitude'], metadata['latitude']]
|
||||
col.insert_one(metadata)
|
||||
|
||||
except:
|
||||
print("Could not insert Metadata")
|
||||
|
||||
decoded_image = WrapperService.unwrap_file(b64encoded_image)
|
||||
|
||||
if not DropboxService.create_file(filename, decoded_image):
|
||||
print("Could not save image to dropbox")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user