The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

401074 (1) [Avatar] Offline
#1
this.resize(width, height) ?
.toBuffer(imageType, function(err, buffer) { ?
if (err) {
next(err);
} else {
next(null, response.ContentType, metadata, buffer);
}
});

imageType is never declared.
mrankin (3) [Avatar] Offline
#2
I don't know if this helps, but this is the message I'm seeing in my logs:

Syntax error in module 'index': SyntaxError at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:373:25) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17)
Danilo Poccia (11) [Avatar] Offline
#3
You are absolutely right! I usually try to clean up code from everything that could distract from the feature I'd like to show, and in my last minute effort I removed the part where I declare the imageType, required to define the picture format to use (for example jpg or png).

I'll fix this for the next update, in the meantime you can declare this function before the "exports.handler = ..." line:

function getImageType(key, callback) {
var typeMatch = key.match(/\.([^.]*)$/);
if (!typeMatch) {
callback("Could not determine the image type for key: ${key}");
return;
}
var imageType = typeMatch[1];
if (imageType != "jpg" && imageType != "png") {
callback('Unsupported image type: ${imageType}');
return;
}
return imageType;
}

You should also add this variable declaration, using the above function, just before the "async.waterfall(..." line:

var imageType = getImageType(srcKey);

I just tested everything and it works for me. Let me know if it is ok for you, thanks!