You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: server/README.md
+40-1Lines changed: 40 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,7 +89,46 @@ With a really big dataset, we'd want to do something better than this. At minim
89
89
90
90
#### Getting the Metadata for a Specific Image
91
91
92
-
TODO
92
+
This route returns all of the metadata about a specific image from Redis. That means every field in the image's Redis Hash except for the one holding the actual image data.
93
+
94
+
One approach to getting all the fields except one would be to just get all of them with the `HGETALL` command, then discard what we don't want in the Flask/Python layer. As the field we don't want contains an entire image and could be several megabytes in size... this is wasteful and causes a lot of unnecessary work on the Redis server and data transfer bandwidth between the Redis server and Flask/Python application.
95
+
96
+
There isn't an "all except" command or variant of `HGETALL`, so instead I'm using the `HMGET command`, passing it a list of every field in the hash except the image data one. This isn't ideal, as if the capture script added more meta data in future I have to adjust the code here to read it and pass it to the front end, but it's what works!
97
+
98
+
```python
99
+
IMAGE_DATA_FIELD_NAME="image_data"
100
+
IMAGE_MIME_TYPE_FIELD_NAME="mime_type"
101
+
IMAGE_TIMESTAMP_FIELD_NAME="timestamp"
102
+
IMAGE_META_DATA_FIELDS= [
103
+
IMAGE_TIMESTAMP_FIELD_NAME,
104
+
IMAGE_MIME_TYPE_FIELD_NAME
105
+
# Anything else that is captured on the Pi can go here.
If the image isn't found, we'll get nothing back and should return a 404 to the front end:
116
+
117
+
```python
118
+
if image_meta_data[0] isNone:
119
+
returnf"Image {image_id} not found.", 404
120
+
```
121
+
122
+
If we did get data, we convert it to a Python dictionary, decoding the String values to UTF-8 and returning the completed dictionary. Flask will return this as a JSON object response to the front end:
0 commit comments