Skip to content

Instantly share code, notes, and snippets.

@matylla matylla/app.js
Created Sep 14, 2016

Embed
What would you like to do?
kraken-async
var async = require("async"),
Kraken = require("kraken"),
fs = require("fs");
var kraken = new Kraken({
api_key: "your-api-key",
api_secret: "your-api-secret"
});
var yourArray = [
"/this/is/file/one",
"/this/is/file/two",
"/this/is/file/three"
];
async.forEach(yourArray, 10, function (filePath, cb) {
// here you process your files with concurrency of 10 at a time
var opts = {
file: fs.createReadStream(filePath),
wait: true
};
kraken.upload(opts, function (data) {
if (data.success) {
console.log('Success. Optimized image URL: %s', data.kraked_url);
} else {
console.log('Fail. Error message: %s', data.message);
}
// this is very important. Calling this callback (cb) tells async
// that this async function is now complete so it can process another one
cb();
});
}, function (err) {
if (err) {
console.log(err);
}
// this is a final callback called only once
// when all files have been processed.
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.