How to use the cloudinary.uploader 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 BOOLRon / watchdog4cloudinary / index.js View on Github external
function performUploadByFilePath(filePath){
    log(`File ${filePath} has been added`);

    // File upload stream
    var stream = cloudinary.uploader.upload_stream(function(result) {
        console.log(result)
        var secure_url = result.secure_url;
        if(secure_url){
            var copy_string = '![](' + secure_url + ')';
            ncp.copy(copy_string,function(){
                notify({
                    type: 'pass',
                    title: '图床',
                    subtitle: '截图上传成功',
                    message: '链接已复制到剪切板',
                    group: 'watchdog4cloudinary',
                });
            });
        }else {

        }
github girliemac / RPi-KittyCam / kittyCam.js View on Github external
function uploadToCloudinary(base64Img, timestamp) {
  cloudinary.uploader.upload(base64Img, (result) => {
    console.log(result);
    publish(result.url, timestamp); // Comment this out if you don't use PubNub
    sendSMS(result.url, timestamp); // Comment this out if you don't use Nexmo
  });
}
github prisma-archive / graphcool-templates / outdated / file-handling / cloudinary-images / cloudinary.js View on Github external
return new Promise(function(resolve, reject) {
    // The `transformation` option performs an on-the-fly image transformation: crops an image to a 200x200 circular thumbnail while automatically focusing on the face
    cloudinary.uploader.upload(userAvatar.file.url, (result) => {
      console.log(result)
      resolve(result)
    }, {
      public_id: 'astroluv/avatars/' + userAvatar.user.id,
      transformation: [
        {width: 200, height: 200, gravity: "face", radius: "max", crop: "thumb"}
      ]
    })
  })
  .then(function (response) {
github keystonejs / keystone-classic / lib / core / render.js View on Github external
// view-specific extensions to the local scope
	_.extend(locals, ext);

	// add cloudinary locals if configured
	if (keystone.get('cloudinary config')) {
		try {
			var cloudinary = require('cloudinary');
			var cloudinaryUpload = cloudinary.uploader.direct_upload();
			locals.cloudinary = {
				cloud_name: keystone.get('cloudinary config').cloud_name,
				api_key: keystone.get('cloudinary config').api_key,
				timestamp: cloudinaryUpload.hidden_fields.timestamp,
				signature: cloudinaryUpload.hidden_fields.signature,
				prefix: keystone.get('cloudinary prefix') || '',
				folders: keystone.get('cloudinary folders'),
				uploader: cloudinary.uploader,
			};
			locals.cloudinary_js_config = cloudinary.cloudinary_js_config();
		} catch (e) {
			if (e === 'Must supply api_key') {
				throw new Error('Invalid Cloudinary Config Provided\n\n'
					+ 'See http://keystonejs.com/docs/configuration/#services-cloudinary for more information.');
			} else {
				throw e;
			}
		}
	}

	res.send(template(locals));
}
github yhagio / kickstarter-clone / src / handlers / profile.js View on Github external
form.parse(req, (err, fields, files) => {

      if (err) {
        req.flash('danger', 'Failed to upload photo. Try again.');
        return res.redirect('/profile/edit');
      }

      const query = { _id: req.user._id };

      // Check if it has image, if not,
      // Assign it to Avatar URL by default
      if (files.profilePhoto.size > 0) {

        cloudinary.uploader.upload(files.profilePhoto.path, (data) => {
        
          // If no errors, retrieve the user and update
          const update = { photo: data.secure_url };

          User.findOneAndUpdate(query, update, (err, user) => {
            if (err) {
              req.flash('danger', 'Could not find the user. Try again.');
              return res.redirect('/profile');
            }

            req.flash('success', 'Successfully uploaded profile photo!');
            return res.redirect('/profile');
          });
        });

      } else {
github keystonejs / keystone-classic / admin / server / routes / index.js View on Github external
cloudinaryScript: false,
		codemirrorPath: codemirrorPath,
		env: keystone.get('env'),
		fieldTypes: keystone.fieldTypes,
		ga: {
			property: keystone.get('ga property'),
			domain: keystone.get('ga domain'),
		},
		keystone: keystoneData,
		title: keystone.get('name') || 'Keystone',
	};

	var cloudinaryConfig = keystone.get('cloudinary config');
	if (cloudinaryConfig) {
		var cloudinary = require('cloudinary');
		var cloudinaryUpload = cloudinary.uploader.direct_upload();
		keystoneData.cloudinary = {
			cloud_name: keystone.get('cloudinary config').cloud_name,
			api_key: keystone.get('cloudinary config').api_key,
			timestamp: cloudinaryUpload.hidden_fields.timestamp,
			signature: cloudinaryUpload.hidden_fields.signature,
		};
		locals.cloudinaryScript = cloudinary.cloudinary_js_config();
	};

	ejs.renderFile(templatePath, locals, {}, function (err, str) {
		if (err) {
			console.error('Could not render Admin UI Index Template:', err);
			return res.status(500).send(keystone.wrapHTMLError('Error Rendering Admin UI', err.message));
		}
		res.send(str);
	});
github goodheads / yourtube / server / controllers / upload.server.controller.js View on Github external
deleteVideo: function(req, res) {
      var publicId = req.params.public_id;

      cloudinary.uploader.destroy(publicId, function(result) {
          console.log(result);
        }, { resource_type: "video" });
    }
};
github codazzo / radvisor / scrapers / events.js View on Github external
imgSprite.write(spritePath, function(err, stdout, stderr, cmd){
                        console.log("image sprite written to disk: " + spriteURL);
                        cloudinary.uploader.upload(spritePath, function(result) {
                            _.each(eventsArray, function(el, index){
                                el.sprite = result.url;
                            });
                            callback(eventsArray);
                        });
                    });
                }
github smooth-code / blog / content / adapters / storage / cloudinary.js View on Github external
return new Promise(function(resolve) {
      cloudinary.uploader.upload(image.path, function(result) {
        resolve(cloudinary.url(result.public_id.concat(".", result.format), cloudinaryImageSetting ).replace('http://', 'https://'));
      });
    });
  }
github urre / kap-cloudinary / index.js View on Github external
const action = async context => {
	const filePath = await context.filePath();

	context.setProgress('Uploading…');

	cloudinary.config({
		cloud_name: context.config.get('cloud_name'),
		api_key: context.config.get('api_key'),
		api_secret: context.config.get('api_secret')
	});

	const upload = cloudinary.uploader.upload(`${filePath}`);

	const response = await upload;

	context.copyToClipboard(response.secure_url);
	context.notify('Cloudinary URL copied to the clipboard');
};