Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从MongoDB检索/读取图像';Python中的GridFS是什么?_Python_Mongodb_Python 3.x_Python Imaging Library_Gridfs - Fatal编程技术网

如何从MongoDB检索/读取图像';Python中的GridFS是什么?

如何从MongoDB检索/读取图像';Python中的GridFS是什么?,python,mongodb,python-3.x,python-imaging-library,gridfs,Python,Mongodb,Python 3.x,Python Imaging Library,Gridfs,我使用上面的代码块来保存图像。问题是,如何取回它并通过一些公共库(如Python3中的PIL)读取它?允许查找使用文件名保存到GridFS的文件 此方法返回可读取的实例 with cv2.imread("Desktop/foo.jpg") as img: b = fs.put(img, filename="foo") 我已尝试将此文件保存回:outfilename=“img.jpg”output=open(outfilename,“wb”)output.write(image),但它不

我使用上面的代码块来保存图像。问题是,如何取回它并通过一些公共库(如Python3中的PIL)读取它?

允许查找使用文件名保存到GridFS的文件

此方法返回可读取的实例

with cv2.imread("Desktop/foo.jpg") as img:
    b = fs.put(img, filename="foo")

我已尝试将此文件保存回:outfilename=“img.jpg”output=open(outfilename,“wb”)output.write(image),但它不起作用。你能帮忙吗?你怎么说它不起作用?怎么了?Nvm。我忘了关闭文件。现在完成了。谢谢你的帮助。
file = fs.find_one({'filename': 'foo'})
image = file.read()