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