Skip to content

DeprecationWarning: isConnected is deprecated and will be removed in the next major version #515

@quiet-node

Description

@quiet-node

Hello, I have tried to use multer-gridfs-storage and got the warning mentioned in the title. Could someone help?

upload.js

const multer = require('multer');
const { GridFsStorage } = require('multer-gridfs-storage');

const MONGO_URL = process.env.MONGO_URL;
const DATABASE = process.env.DATANASE;
const IMAGE_BUCKET = process.env.IMAGE_BUCKET;

const storage = new GridFsStorage({
  url: MONGO_URL + DATABASE,
  options: { useNewUrlParser: true, useUnifiedTopology: true },
  // file is the function to control the file storage in the database
  file: (req, file) => {
    const match = ['image/png', 'image/jpeg'];

    if (match.indexOf(file.mimetype) === -1) {
      const filename = `${Date.now()}-J4I-${file.originalname}`;
      return filename;
    }

    return {
      bucketName: IMAGE_BUCKET,
      filename: `${Date.now()}-J4I-${file.originalname}`,
    };
  },
});

// Multer module initializes middleware
const uploadFiles = multer({ storage: storage }).single('file');

// util.promisify() makes the exported middleware object can be used with async/await
const uploadFilesMiddleware = util.promisify(uploadFiles);
module.exports = uploadFilesMiddleware;

.env

## MongoDB
MONGO_URL='mongodb://localhost:27017/'
DATABASE='J4I_files_db'
IMAGE_BUCKET='photos'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions