tfse-app-api-v0.2/file/db.py

23 lines
556 B
Python

import pymongo
from bson import ObjectId
from gridfs import GridFS
client = pymongo.MongoClient('mongodb://{}:{}@{}:{}'.format('root', 'sromitdTW569kC#M', '116.63.130.34', 27018))
def find_file(bucket, file_id):
"""
读取一个文件
Parameters:
bucket:
file_id:
Returns:
data 文件二进制
"""
# 实例化一个文件存储器
gfs = GridFS(client['评价'], collection=bucket)
# 二进制读取文件
data = gfs.get(ObjectId(file_id)).read()
# 返回文件二进制流
return data