问题描述:

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?

网友答案:

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.

网友答案:

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

相关阅读:
Top