Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function logExampleJSON(){
console.warn("Example:")
var exampleJSON = {
cloud_name: 'your cloud name',
api_key: 'your api key',
api_secret: 'your api secret'
};
console.log(prettyjson.render(exampleJSON, {
noColor: false
}));
}
var configDic = JSON.parse(fs.readFileSync(confPath,'utf8'))
if (configDic) {
cloudinary.config(configDic);
}else {
console.warn("config file format errorh");
logExampleJSON();
progress.exit();
}
if (!fs.existsSync(syncDirPath)){
fs.mkdirSync(syncDirPath);
}
function performUploadByFilePath(filePath){
log(`File ${filePath} has been added`);
// File upload stream
var stream = cloudinary.uploader.upload_stream(function(result) {
console.log(result)
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");
});
// $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
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 {
}
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
});
}
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) {
* uploadAvatar (request, response) {
var imageFile = request.file('avatar').tmpPath()
// Upload file to Cloudinary
const upload = thunkify(cloudinary.uploader.upload)
try {
const image = yield upload(imageFile)
const loginID = yield request.auth.getUser()
yield UserRepository.saveAvatar(loginID, image.url)
yield request.with({status: 'Avatar has been updated successfully'}).flash()
response.redirect('back')
} catch (e) {
console.log(e)
yield request.with({status: 'Error in updating your avatar '}).flash()
response.redirect('back')
}
}
next();
}
// upload image to cloudinary.com
var config = {
cloud_name: '',
api_key: '',
api_secret: ''
};
if (config.api_secret) {
var cloudinary = require('cloudinary'),
fs = require('fs'),
path = require('path');
cloudinary.config(config);
}
exports.postSave = function (req, res, args, next) {
if (args.debug) console.log('postSave');
debugger;
// upload image to a third party server
if (args.name == 'item') {
// provide your credentials to cloudinary.com
if (!config.api_secret) return next();
// file upload control data
var image = args.upload.view.item.records[0].columns.image;
// in case file is chosen through the file input control
if (image.name) {
// file name of the image already uploaded to the upload folder
var fname = args.data.view.item.records[0].columns.image;
new Promise((yay, nay) => {
cloudinary.api.resources(
(result) => {
if (result.error) {
return nay(result.error);
}
// Aktuelle Bilder an Ausgabe-Array anhängen (max 500)
const results =
result.resources && result.resources.length
? images.concat(result.resources.map(transform))
: [];
// Falls noch weitere Bilder in Mediathek sind, diese auch laden
if (result.next_cursor) {
console.error('WARNING, MORE THAN 500 IMAGES!');
return getImages(config, results, result.next_cursor).then(yay);
}
.then((res) => res.arrayBuffer())
.then(arrayBufferToBuffer)
.then((res) => resolve(res))
.catch((err) => {
console.log("error trimming screenshot");
console.log(err);
resolve(screenshot);
});
});
};
/* Upload Screenshot with Cloudinary *********************** */
const cloudinary = require('cloudinary').v2;
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET
});
const uploadScreenshot = (feature, screenshot) => {
return new Promise((resolve, reject) => {
const options = {
folder: 'caniuse-embed/static',
public_id: `${feature}-${new Date().getTime()}`
};
cloudinary.uploader.upload_stream(options, (error, result) => {
if (error) reject(error)
else resolve(result);