I need to download an image when it arrives in Dropbox and upload to Azure Storage. I am doing this using a Kubeless serverless function which is triggered by Dropbox's push notification. This download and upload is working fine. However, I'd like to access the image's exif data so I can send metadata about the image to a RabbitMQ queue. When I try and open the image to use with Python's Pillow or exif modules I get this error:
'UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte'
dbx = dropbox.Dropbox(os.environ['DROPBOX_TOKEN'])
for entry in dbx.files_list_folder('').entries:
print('File found: ' + entry.name)
md, response = dbx.files_download('/' + entry.name)
file_stream = response.content
# Code to upload to Azure Storage and delete file from Dropbox here
I've tried:
with open(file_stream, 'rb') as data:
# do things with file
And using Pillow:
image = Image.open(file_stream)
image.show()
And get same error with each. I'm new to using Python and working with files this way so any help would be appreciated.