cloudinary / cloudinary_npm

Cloudinary NPM for node.js integration
629 stars 323 forks source link

Folder parameter don't work #587

Closed EdsenxX closed 1 year ago

EdsenxX commented 1 year ago

Describe the bug in a sentence or two.

When uploading an image using the cloudinary SDK from nextjs and defining the folder where I want it to be stored, it simply ignores it and uploads it to the root.

Issue Type (Can be multiple)

[ ] Build - Can’t install or import the SDK [ ] Babel - Babel errors or cross browser issues [ ] Performance - Performance issues [x] Behaviour - Functions aren’t working as expected (Such as generate URL) [x] Documentation - Inconsistency between the docs and behaviour [ ] Incorrect Types - For typescript users who are having problems with our d.ts files [ ] Other (Specify)

Steps to reproduce

import cloudinary from "cloudinary";

cloudinary.v2.config({
    cloud_name: process.env.CLOUDINARY_NAME,
    api_key: process.env.CLOUDINARY_KEY,
    api_secret: process.env.CLOUDINARY_SECRET
})

export default cloudinary
const uploadedImageResponse = await cloudinary.uploader.upload(image.buffer, {
      folder: "portafolio/skills",
    })

I tried using folder, public_id, and asset_folder and none of them worked for me.

Error screenshots

This is the response I have, the folder is simply ignored.

uploadedImageResponse >>>> {
  asset_id: 'ed598ed7bd9c93e28744a695303c9351',
  public_id: 'kuim8oqnuzl4lugizmld',
  version: 1675746924,
  version_id: '24823b2b0520f155f331466722809ae2',
  signature: 'ef60bbd3000d12e90b72cf9dffe0ce4ed7e56165',
  width: 30,
  height: 30,
  format: 'png',
  resource_type: 'image',
  created_at: '2023-02-07T05:15:24Z',
  tags: [],
  bytes: 874,
  type: 'upload',
  etag: 'e1e912fea5a5ac5ce894d4e47e2ee374',
  placeholder: false,
  url: 'http://res.cloudinary.com/edsen/image/upload/v1675746924/kuim8oqnuzl4lugizmld.png',
  secure_url: 'https://res.cloudinary.com/edsen/image/upload/v1675746924/kuim8oqnuzl4lugizmld.png',
  folder: '',
  api_key: '342793654176641'
}

Versions and Libraries

Cloudinary_NPM SDK version Node - 18.4.0 NPM - 8.12.1

Config Files

Package.json

{
  "name": "portafolio-next",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@hookform/resolvers": "^2.9.10",
    "@types/node": "18.11.17",
    "@types/react": "18.0.26",
    "@types/react-dom": "18.0.9",
    "axios": "^1.3.2",
    "body-parser": "^1.20.1",
    "cloudinary": "^1.33.0",
    "compressorjs": "^1.1.1",
    "cors": "^2.8.5",
    "eslint": "8.30.0",
    "eslint-config-next": "13.0.7",
    "jsonwebtoken": "^9.0.0",
    "moment": "^2.29.4",
    "mongoose": "^6.9.0",
    "mongoose-bcrypt": "^1.10.1",
    "multer": "^1.4.5-lts.1",
    "next": "13.0.7",
    "next-connect": "^0.13.0",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-hook-form": "^7.43.0",
    "sass": "^1.57.1",
    "sweetalert": "^2.1.2",
    "typescript": "4.9.4",
    "yup": "^0.32.11"
  },
  "devDependencies": {
    "autoprefixer": "^10.4.13",
    "postcss": "^8.4.20",
    "tailwindcss": "^3.2.4"
  }
}
momoip commented 1 year ago

Hi @EdsenxX ,

You can use:

import cloudinary from "cloudinary.v2"

Best regards, Mo

EdsenxX commented 1 year ago

HI @momoip, that does not work for me, I have the next error

image

aleksandar-cloudinary commented 1 year ago

Hi @EdsenxX , could you please try to import it like so:

let cloudinary = require('cloudinary').v2;

Or, alternatively, you could replace cloudinary.uploader.upload with cloudinary.v2.uploader.upload

Please let us know how it goes.

EdsenxX commented 1 year ago

@aleksandar-cloudinary thank you, that worked for me, I replace cloudinary.uploader.upload with cloudinary.v2.uploader.upload