Hi, I'm trying to get access to "gfs" variable from MyGridFS class in controller file but whatever I'm trying I'm getting undefined error and I'm run out of ideas how can I salve this.(Controller file also is based on class.)
class MyGridFS {
constructor() {
let gfs = this.gfs;
let gridfsBucket = this.gridfsBucket;
}
initializeGridFS(conn) {
this.conn = conn;
conn.once("open", () => {
this.gridfsBucket = new mongoose.mongo.GridFSBucket(conn.db, {
bucketName: "uploads",
});
this.gfs = Grid(conn.db, mongoose.mongo);
this.gfs.collection("uploads");
});
}
initializeStorage(mongo_uri) {
this.mongo_uri = mongo_uri;
const storage = new GridFsStorage({
url: this.mongo_uri,
file: (req, file) => {
const filename = "file_" + Date.now() + path.extname(file.originalname);
return {
filename,
bucketName: "uploads",
};
},
});
this.upload = multer({ storage });
}
}