3

I am using pymongo to store user comments in my Django project. I need to save comment images to the database and then show it on a page which is generated by a Django template, but when I use request.FILES.get (...), read(...), the line does not save in Mongo, because it is not encoded in utf-8.

How can I properly save an image into mongoDB and then show on an HTML page?

CoffeeRain
  • 4,460
  • 4
  • 31
  • 50
  • possible duplicate of [saving picture to mongodb](http://stackoverflow.com/questions/11915770/saving-picture-to-mongodb) – jdi Aug 11 '12 at 18:58

2 Answers2

5

You can try and use this api section: http://api.mongodb.org/python/2.2.1/api/bson/binary.html

Wrap it inside of this object and then try and insert/save it.

Disclaimer: I have never programmed python so I might be talking jibberish about the wrapping part, either way that page should tell you how to do it.

jdi
  • 90,542
  • 19
  • 167
  • 203
Sammaye
  • 43,242
  • 7
  • 104
  • 146
1

Have you tried GridFS? It's a great tool for storing binary data like images in a database.

CoffeeRain
  • 4,460
  • 4
  • 31
  • 50
NIlesh Sharma
  • 5,445
  • 6
  • 36
  • 53