Python Forum

Full Version: Retrieve images base64 encoded MongoDB and Flask
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm developing simple web application using flask , scrapy and mongodb. In my case crawl webpages and store some data in mongodb collection and represent using flask. I stored some images in mongodb as binary. Now I want to retrieve that binary data as images via flask. Currently I retrieved some stored data like this 
<a href="{{ page._id.url }}">{{ page._id.title }}</a>
<p class="mb-4">{{ get_excerpt(page._id.content, q) }}</p>
Now I want to display the images which saved as binary in mongo collection. Collection name is 'page' and stored as 
 
"image": {
        "$binary": {
            "base64": "iVBORw0KGgoAAAANSUhEUgAAAw8AABD+CAYAAAAbJKU5AAAAAXNSR0IArs4c6QAAIABJREFUeJzsvXmYJEd5J/yLyKyrr+nu0dwz/xaprA..................ACAs/weX+u+movGYcQAAAABJRU5ErkJggg=="
 Is there any way to do that?
Why do you need to store the images in the database in the first place? If all you want to do later is display them on a page, I fear you're just introducing unnecessary complexity by doing so. You'd be better off storing them on a file system, as I mentioned in one of your earlier threads. Do you have a good reason for needing to store them in the database?
Actually I want if anyone access file system, he can't be find an Image easily and so stored images as binary in db collections.