Retrieve images base64 encoded MongoDB and Flask - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Retrieve images base64 encoded MongoDB and Flask (/thread-30266.html) |
Retrieve images base64 encoded MongoDB and Flask - Nuwan16 - Oct-13-2020 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? RE: Retrieve images base64 encoded MongoDB and Flask - ndc85430 - Oct-13-2020 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? RE: Retrieve images base64 encoded MongoDB and Flask - Nuwan16 - Oct-13-2020 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. |