affanshahid / multer-storage-cloudinary

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

cloudinary version ^2.2.0 isn't supported because multer-storage-cloudinary uses ^1.21.0 as peer are dev Dependence #53

Open Itszavier opened 5 months ago

Itszavier commented 5 months ago
! While resolving: backend@1.0.0
npm ERR! Found: cloudinary@2.2.0
npm ERR! node_modules/cloudinary
npm ERR!   cloudinary@"^2.2.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer cloudinary@"^1.21.0" from multer-storage-cloudinary@4.0.0
npm ERR! node_modules/multer-storage-cloudinary
npm ERR!   multer-storage-cloudinary@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

This happens because the multer-storage-cloudinary supports a older version of the cloudinary sdk

AmanJaiswal2001 commented 4 months ago

this is my same error how can solve it ! While resolving: backend@1.0.0 npm ERR! Found: cloudinary@2.2.0 npm ERR! node_modules/cloudinary npm ERR! cloudinary@"^2.2.0" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer cloudinary@"^1.21.0" from multer-storage-cloudinary@4.0.0 npm ERR! node_modules/multer-storage-cloudinary npm ERR! multer-storage-cloudinary@"*" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Itszavier commented 4 months ago

@AmanJaiswal2001 i solve this error by just using the cloudinary sdk to upload

npm i cloudinary
import express from "express";
import dotenv from "dotenv";
import { v2 as cloudinary } from "cloudinary";

dotenv.config();
const app = express();
cloudinary.config({
  cloud_name: process.env.CLOUDINARY_NAME,
  api_key: process.env.CLOUDINARY_API_KEY as string,
  api_secret: process.env.CLOUDINARY_API_SECRET,
});

app.get('upload',  multer.single('image'),  (req,res, next) => {
 const upload_stream = cloudinary.uploader.upload_stream(
        {
          public_id: '...id',
          resource_type: "auto", // Assume auto-detect the resource type
          folder: folder,
        },
        (error, results) => {
          if (error) {
            console.error("Error uploading image:", error);

          } else {
            console.log("Uploaded image:", results);
            console.log(results);
          }
        }
      );
    upload_stream.end(req.file.buffer);
}

This was my quick solution