UNPKG

cky-image-public

Version:

public image to public host

37 lines (29 loc) 743 B
const fs = require("fs"); let helper = require('../helper'); class Cloudinary { constructor (options = {}) { let { api_key, api_secret, cloud_name } = options; this.cloudinary = require('cloudinary').v2; if (!process.env.CLOUDINARY_URL) { this.cloudinary.config({ cloud_name, api_key, api_secret, }); } } upload (imgPath, options = {}, callback) { let tags = null; if (typeof options == 'function') { callback = options } else { tags = options.tags; } this.cloudinary.uploader.upload(imgPath, { tags }) .then( (image) => { return callback(null, image); }) .catch(err => callback(err)) } } module.exports = Cloudinary;