Python Forum
Retrieve images base64 encoded MongoDB and Flask
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Retrieve images base64 encoded MongoDB and Flask
#1
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?
Reply
#2
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?
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to send unicode string encoded in utf-8 in http request in Python MaverinCode 1 32,354 Nov-08-2020, 06:45 AM
Last Post: JaiM
  Store Screenshot Selenium + MongoDB Nuwan16 9 3,526 Aug-18-2020, 03:57 AM
Last Post: ndc85430
  filtering by category flask+mongodb Leon79 3 7,921 Jul-19-2020, 04:25 AM
Last Post: ndc85430
  error when trying to update mongodb damian0612 6 3,365 Jul-04-2020, 07:25 PM
Last Post: damian0612
  Extract json-ld schema markup data and store in MongoDB Nuwan16 0 2,413 Apr-05-2020, 04:06 PM
Last Post: Nuwan16
  flask app to save images locally when deployed on heroku not working Prince_Bhatia 1 5,231 Feb-20-2019, 11:59 PM
Last Post: snippsat
  Flask rest api How to retrieve json request raysefo 4 6,014 Jan-20-2019, 06:46 PM
Last Post: raysefo
  storing images in mongodb using python richa828 2 9,319 Jun-06-2018, 08:08 AM
Last Post: richa828
  Begginer - How to choose a server to run my Python script with MongoDB? Mapl 1 3,710 Oct-24-2017, 01:02 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020