Skip to content Skip to sidebar Skip to footer

What Data 'structure' Does Fs.get_last_version Return?

When I use get_last_version to get an image from the database, what is actually returned ie an array, the merged binary data of all the chunks that make up the file (as a string),

Solution 1:

Unless there is a better answer, this is what I've come up with.

get_last_version returns a Binary() object.

In regards to base64 encoding it, and returning it, this is how I did it:

dbname = 'grid_files'
db = connection[dbname]
fs = gridfs.GridFS(db)
filename = "my_image.jpg"
my_image_file = fs.get_last_version(filename=filename)
encoded_img_file = base64.b64encode(my_image_file.read())
return encoded_img_file

Then accessed it on the front end with:

$("#my_img").attr("src", "data:image/png;base64," + data);

Post a Comment for "What Data 'structure' Does Fs.get_last_version Return?"