我正在尝试使用GridFS和Mongoose将视频上传到数据库,但它将Bucket Name保持为fs
let gfss;
const conn = mongoose.createConnection('mongodb://localhost:27017/zaad');
conn.once('open',()=>{
gfss = Grid(conn.db,mongoose.mongo);
gfss.collection('lessonVideo');
});
const storage = new GridFsStorage({
url:config.uri,
file:(req,file)=>{
if(!req.params.id){
console.log('no id provided');
}else{
User.findOne({_id:req.decoded.user},(err,user)=>{
if(err){
console.log(err);
}else{
Lesson.findOne({_id:req.params.id},(err,lesson)=>{
if(err){
console.log(err);
}else{
if(!lesson){
console.log('lesson does not exits');
}else{
if(lesson.createbById == req.decoded.userId){
return new Promise((resolve,reject)=>{
crypto.randomBytes(16,(err,buf)=>{
if(err){
return reject(err);
}
const filename = buf.toString('hex')+ path.extname(file.originalname);
const metadata = req.params.id;
const fileinfo = {
filename:filename,
metadata:metadata,
bucketName:'lessonVideo'
};
resolve(fileinfo);
});
});
}else{
console.log('your not authentication to this file');
}
}
}
});
}
});
}
}
});
const upload = multer({storage});
router.post('/lessonVideo/:id',upload.single('file'),(req,res)=>{
if(!req.file){
res.json({success:false , message:'no image was provided'});
}else{
console.log(req.decoded.userId);
res.json({success:true , message:'done'});
}
});
但它保留了存储桶名称fs
当我删除它工作的所有if
语句但当我使用它们时,存储桶名称更改为fs