I am sending images from a Raspberry Pi to Cloud IoT Core. This is working, but I now realised that I also need the filename of the file (or the data that I have added to the filename), when storing it in Google Cloud Storage, but as far as I can see it is only the content of the file that is sent. I have tried to accomplish this with the code extract below, but this doesn't seem to work, which I guess is understandable seeing that it is a byte array inside a JSON object..?
Is there a way at all? Is the filename somehow retrievable when sending via Cloud Function to Storage?
with open(filename, 'rb') as f:
imagestring = f.read()
byteArray = bytes(imagestring)
now = datetime.datetime.now()
datetime_formatted = now.strftime("%Y-%m-%d_%H:%M:%S")
filename = 'img_GM4_' + datetime_formatted +'.jpg'
payload = '{{ "ts": {}, filename: {}, "image": {}}}'.format(int(time.time()), filename, byteArray)
client.publish(_MQTT_TOPIC, payload, qos=1)
# Previously: client.publish(_MQTT_TOPIC, byteArray, qos=1)