How to use the cloudinary.v2 function in cloudinary

To help you get started, we’ve selected a few cloudinary examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudinary / cloudinary_npm / samples / basic / basic.js View on Github external
require('dotenv').load();
var fs = require('fs');
var cloudinary = require('cloudinary').v2;

var uploads = {};

// set your env variable CLOUDINARY_URL or set the following configuration
/* cloudinary.config({
  cloud_name: '',
  api_key: '',
  api_secret: ''
}); */

console.log("** ** ** ** ** ** ** ** ** Uploads ** ** ** ** ** ** ** ** ** **");

// File upload
cloudinary.uploader.upload('pizza.jpg', { tags: 'basic_sample' }, function (err, image) {
  console.log();
  console.log("** File Upload");
github cloudinary / cloudinary_npm / types / cloudinary_ts_spec.ts View on Github external
});

// $ExpectType Promise
cloudinary.v2.api.transformation({width: 150, height: 100, crop: 'fill'},
    function (error, result) {
        console.log(result, error);
    });

// $ExpectType Promise
cloudinary.v2.api.transformation('w_150,h_100,c_fill',
    function (error, result) {
        console.log(result, error);
    });

// $ExpectType Promise
cloudinary.v2.api.transformations(function (error, result) {
    console.log(result);
});

// $ExpectType Promise
cloudinary.v2.api.update_resources_access_mode_by_ids("public", ['image1', 'image2'],
    function (error, result) {
        console.log(result);
    });

// $ExpectType Promise
cloudinary.v2.api.update_resources_access_mode_by_tag('public', "20170216",
    function (error, result) {
        console.log(result);
    });

// $ExpectType Promise
github streetmix / streetmix / app / resources / v1 / users_pg.js View on Github external
const handleUserProfileImage = async function (user, credentials) {
    const publicId = `${config.env}/profile_image/${user.id}`
    let profileImageUrl

    // Check if user has profile image already cached in cloudinary
    if (user.profile_image_url && user.profile_image_url.includes(publicId)) {
      profileImageUrl = user.profile_image_url
    } else if (credentials.profile_image_url) {
      // If no profile image cached in cloudinary, cache image provided by credentials and return cloudinary url.
      try {
        const response = await cloudinary.v2.uploader.upload(
          credentials.profile_image_url,
          { upload_preset: 'profile_image', public_id: publicId }
        )
        profileImageUrl = response.secure_url
      } catch (error) {
        logger.error(error)
        // If unable to cache image, return credentials.profile_image_url.
        profileImageUrl = credentials.profile_image_url
      }
    }

    return profileImageUrl
  }
github webhintio / hint / packages / hint-image-optimization-cloudinary / src / hint.ts View on Github external
/*
             * Using the MD5 hash of the file is the recommended way to avoid duplicates
             * https://support.cloudinary.com/hc/en-us/articles/208158309-How-can-I-completely-prevent-the-existence-of-image-duplications-on-my-Cloudinary-account-
             */
            const hash = crypto
                .createHash('md5')
                .update(data.response.body.rawContent)
                .digest('hex');

            const tempPath = path.join(tmpdir(), 'hint-cloudinary', hash);

            try {
                await fs.ensureFile(tempPath);
                await fs.writeFile(tempPath, data.response.body.rawContent);

                const result = await cloudinary.v2.uploader.upload(tempPath, { crop: 'limit', public_id: hash, quality: 'auto' });

                result.originalBytes = data.response.body.rawContent.length;
                result.originalUrl = data.resource;
                result.element = data.element;

                await fs.remove(tempPath);

                return result;
            } catch (error) {
                logger.error(getMessage('errorProcessingImage', context.language, cutString(data.resource)));
                logger.error(error);

                // We still want to complete the test
                return null;

            }
github cloudinary / cloudinary_npm / samples / photo_album / controllers / photos_controller.js View on Github external
var cloudinary = require('cloudinary').v2;
var crypto = require('crypto');
var multipart = require('connect-multiparty');
var schema = require('../config/schema');

var Photo = schema.models.Photo;

var multipartMiddleware = multipart();

function index(req, res) {
  Photo.all().then(function (photos) {
    res.render('photos/index', { photos: photos });
  });
}

function add_through_server(req, res) {
  // Create a new photo model and set it's default title
github streetmix / streetmix / app / resources / v1 / street_images.js View on Github external
const handleUploadStreetThumbnail = async function (publicId) {
    if (!publicId) {
      res.status(400).json({ status: 400, msg: 'Please provide the public ID to be used.' })
      return
    }

    try {
      await cloudinary.v2.uploader.remove_all_tags([publicId])
      resource = await cloudinary.v2.uploader.upload(image, { public_id: publicId, tags: editCount })
    } catch (error) {
      logger.error(error)
    }

    if (!resource) {
      res.status(500).json({ status: 500, msg: 'Error uploading street thumbnail.' })
      return
    }

    logger.info({ event, ...details }, 'Uploading street thumbnail.')
    return resource
  }
github iamraphson / adonisjs-hackathon-starter / app / Http / Controllers / AccountController.js View on Github external
/**
 * Created by Raphson on 12/23/16.
 */
'use strict'

const Validator = use('Validator')
const fs = require('fs')
const Helpers = use('Helpers')
const UserRepository = make('App/Repositories/UserRepository')
const path = require('path')
const cloudinary = require('cloudinary').v2
const thunkify = require('thunkify')

class AccountController {

  constructor () {
    const file = Helpers.resourcesPath('locales/en/validation.json')
    this.messages = JSON.parse(fs.readFileSync(file, 'utf8'))
  }

  * edit (request, response) {
    this.loginID = yield request.auth.getUser()
    const loggedinUser = yield UserRepository.findUserById(this.loginID.id)
	  const userProfile = yield loggedinUser.profile().fetch()
	  let linkedAccount = userProfile.toJSON().map(function (profile) {
		  return profile.provider
	  })
github DimiMikadze / create-social-network / api / utils / cloudinary.js View on Github external
return new Promise((resolve, reject) => {
    const streamLoad = cloudinary.v2.uploader.upload_stream(
      options,
      (error, result) => {
        if (result) {
          resolve(result);
        } else {
          reject(error);
        }
      }
    );

    stream.pipe(streamLoad);
  });
};
github ReactFinland / graphql-api / server / routes / resolve-image.ts View on Github external
async function uploadToCloudinary(source: string, resourceId: string) {
  try {
    const uploadedAsset = await cloudinary.v2.uploader.upload(source, {
      overwrite: true,
      public_id: resourceId,
    });
    const imageUrl = uploadedAsset.secure_url;

    resources.push({ id: resourceId, url: imageUrl });

    return imageUrl;
  } catch (err) {
    throw new Error(err.message);
  }
}
github Urigo / WhatsApp-Clone-Server / modules / user / providers / user.provider.ts View on Github external
return new Promise((resolve, reject) => {
      cloudinary.v2.uploader.upload(filePath, (error, result) => {
        if (error) {
          reject(error);
        } else {
          resolve(result);
        }
      })
    });
  }