python - Retrieve file from mongoDB using python
问题描述
I have doc file stored in mongodb. I want to retrieve stored doc file on mongoDB using python. Any suggestion will really be helpful. I'm unable to find article to move forward. All I could find is uploading file through python and retrieving through python. But I want to retrieve file stored on mongoDB which is not created on python but retrieving through python. P.S.: I stored file on mongodb gridfs using express js.
Upload.JS:: JS used to upload file on mongodb gridfs .
const util = require("util");
const multer = require("multer");
const GridFsStorage = require("multer-gridfs-storage");
const mongoose = require('mongoose');
const Grid = require('gridfs-stream');
const mongoURI ='mongodb://localhost:27017/file_uploaded_new';
const promise = mongoose.connect(mongoURI, { useNewUrlParser: true });
const conn = mongoose.connection;
let gfs;
conn.once('open',() => {
gfs = Grid(conn, mongoose.mongo);
gfs.collection('uploads');
});
var storage = new GridFsStorage({
db: promise,
options: {useNewUrlParser: true, useUnifiedTopology: true },
file: (req, file) => {
return new Promise((resolve, reject) => {
if (file.mimetype === 'application/vnd.openxmlformats-
officedocument.wordprocessingml.document') {
resolve({
bucketName: 'words',
filename: `${file.originalname}`
})
} else {
reject(Error("File type has been rejected"));
}
});
}
});
var uploadFile = multer({storage: storage}).single("file");
var uploadFilesMiddleware = util.promisify(uploadFile);
module.exports = uploadFilesMiddleware;
I have successfully uploaded docx file in MongoDB. How can I retrieve the uploaded word file using python script?
解决方案
推荐阅读
- flutter - 来自特定日期的查询线程(SMS)fluter / sms_advanced
- javascript - 如何将字符串数组的数组转换为一个对象,其中每个字符串是包含下一个对象的对象的键
- scala - 进行 2 个基于未来的调用时的错误处理和恢复
- windows - 本地主机:8080 - 此网站不可用
- r - 如何进行精确测试以测试结果的 3 个级别是否等于 R 中的某些比例?
- java - 我需要使用 Java 代码从 .xls 文件中删除下拉列表
- javascript - nodejs webcrypto imporKey rsa 错误“错误:0D07207B:asn1 编码例程:ASN1_get_object:header too long”
- javascript - 网页截图部分变黑
- reactjs - 解析错误:找不到模块'@babel/preset-react'
- java - docker 映像中的 Tomcat webapp 部署仅在 linux 机器上失败