Python3操做MongoDB存储图片

推荐阅读数据库

from io import BytesIO

import bson
import pymongo
import requests

conn = pymongo.MongoClient(host='127.0.0.1', port=27017)
db = conn.数据库名
collection = db.表名

img = BytesIO(requests.get(url='图片连接').content)
collection.save(dict(_id='ID', img=bson.binary.Binary(img.getvalue())))

conn.close()
复制代码
相关文章
相关标签/搜索