'Converting S3 object body to String in Redis for cache and back to bytes in Python for downloading
I have objects that inside of an S3 Bucket in zip folders, that is queried by an API Server, that a Python 3* package makes requests to and then downloads the data.
Currently, if the API Server simply forwards the object Body to the Python package it does not have issues. However, if I cache the Body inside of Redis I am getting errors.
Here is what the Body looks like from S3 - Body: <Buffer 50 4b 03 04 14 00 00 00 08 00 e1 8c 76 53 54 68 49 be 94 98 02 00 a2 9a 02 00 20 00 00 00 30 30 2d 33 30 2d 35 33 2d 32 37 2d 63 38 2d 61 61 2f 32 30 ... 437122 more bytes>
First, if I cache the Body as is, then Redis is giving me nil, so I solved this by casting the Body to a String.
redis.set(cacheKey, String(obj.Body));
But now I am having issues converting the String representation of the Body back into its original format for downloading despite multiple attempts of using encode() and bytes() functions in Python.
Could someone help me convert this into a downloadable format like so?
open('data.zip', 'wb').write(data)
I am also open to different suggestions.
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
