Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
quiet-node opened this issue Oct 2, 2022 · 0 comments

Comments

@quiet-node
Copy link

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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant