Python Forum
storing images in mongodb using python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
storing images in mongodb using python
#1
How do I store and retrieve/display images in mongodb.I am working with Pycharm as the editor .
when I upload a file through html and try to store it generally then only the name of the image is getting stored. I want to display the images stored in a new html page.
Richa.
Reply
#2
Show the code you use and html page where you want to display the image. We don't even know what modules you use.
Reply
#3
My python code is as follows:

from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.template import loader
from django.views.decorators.csrf import csrf_exempt
from pymongo import MongoClient
import gridfs
client = MongoClient('localhost:27017')
# disabling csrf (cross site request forgery)
@csrf_exempt
def index(request):
    # if post request came
    if request.method == 'POST':
        db = client.rich
        st=request.POST.get('pic',0);
        db.Employees.insert(
            {
            "pic": st
            }
        )
        item=db.Employees.find({})
        for x in item:
            html = "<html><body><img src='%s'></body></html>", x['pic']
        return HttpResponse(html)

    else:

        template = loader.get_template('index.html')
        return HttpResponse(template.render())
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Retrieve images base64 encoded MongoDB and Flask Nuwan16 2 3,233 Oct-13-2020, 06:25 PM
Last Post: Nuwan16
  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,918 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,412 Apr-05-2020, 04:06 PM
Last Post: Nuwan16
  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