affanshahid / multer-storage-cloudinary

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

Expected response #17

Closed Enado95 closed 4 years ago

Enado95 commented 4 years ago

I realize that response differs from what is in the Cloudinary docs. This is the response that is returned when I use this package:

{
  fieldname: 'logoUrl',
  originalname: 'Screen Shot 2020-05-11 at 4.56.29 PM.png',
  encoding: '7bit',
  mimetype: 'image/png',
  path: 'https://res.cloudinary.com/dv9lwnsxc/image/upload/v152333339/veme/frrl9san8jhbzkuibu92jj3p.png',
  size: 74024,
  filename: 'folderName/frrl9san8ak0v1evjj3p'
}

Cloudinary docs states that the response should be like below:

{ 
  public_id: 'cr4mxeqx5zb8rlakpfkg',
  version: 1571218330,
  signature: '63bfbca643baa9c86b7d2921d776628ac83a1b6e',
  width: 864,
  height: 576,
  format: 'jpg',
  resource_type: 'image',
  created_at: '2017-06-26T19:46:03Z',
  bytes: 120253,
  type: 'upload',
  url: 'http://res.cloudinary.com/demo/image/upload/v1571218330/cr4mxeqx5zb8rlakpfkg.jpg',
  secure_url: 'https://res.cloudinary.com/demo/image/upload/v1571218330/cr4mxeqx5zb8rlakpfkg.jpg' 
}

here's my code

const multer = require('multer')
const cloudinary = require('cloudinary').v2
const { CloudinaryStorage } = require('multer-storage-cloudinary')

cloudinary.config({
  cloud_name: process.env.CLOUD_NAME,
  api_key: process.env.CLOUD_API_KEY,
  api_secret: process.env.CLOUD_API_SECRET
})

const storage = new CloudinaryStorage({
  cloudinary: cloudinary,
  params: {
    folder: process.env.CLOUD_FOLDER,
    allowedFormats: ['jpg', 'png', 'jpeg'],
    transformation: [{ width: 500, height: 500, crop: 'limit' }]
  }
})

const parser = multer({
  storage: storage
})

module.exports = parser

Were the fields renamed and some removed intentionally?

affanshahid commented 4 years ago

Yes, they were renamed and removed intentionally. The multer types define the File type that we use. The reason I did this was because I wanted to remain as close to the types defined for multer. However, I suppose we could also keep all the other properties from the response along with the multer file properties.

Enado95 commented 4 years ago

Understood, it makes sense especially path instead of url and secured_url. Either way your app will more than likely be over https so the url key value pair won't never be used. Thanks for clarifying.