affanshahid / multer-storage-cloudinary

A Cloudinary multer storage engine
MIT License
104 stars 18 forks source link

How to specify multiple folder? #32

Closed KongkaMozumderSUST closed 3 years ago

KongkaMozumderSUST commented 3 years ago

I am creating an express app Studentforum like any social media with my friend. Initially we are using Cloudinary for storing images and we want to be put profile pictures(storage) and post's images(storage2) in different folders. While using 'storage' everything works fine but for 'storage2', an image buffer is created instead of URL and in cloudinary no folder named 'StudentForumPosts' is being created by the code. The following code I am using for cloudinary 'index.js':

const cloudinary = require('cloudinary').v2;
const {CloudinaryStorage}=require('multer-storage-cloudinary');
cloudinary.config({
    cloud_name: process.env.CloudinaryCloudName,
    api_key: process.env.CloudinaryKey,
    api_secret: process.env.CloudinaryApiSecret
});
const storage = new CloudinaryStorage({
    cloudinary,
    params: {
    folder:'StudentForum',
    allowedFormats: ['jpg','png','jpeg'],
    transformation: [{
        width: 300,
        height: 300,
        gravity: "faces",
        crop: "fill"

    }],
    }
});
const storage2 = new CloudinaryStorage({
cloudinary,
params: {
folder:'StudentForumPosts',
allowedFormats: ['jpg','png','jpeg']
}
});
module.exports = {
    cloudinary,
    storage,
    storage2
}