Tools to Capture and Convert the Web

Handler with Node.jsNode.js API

Description

Having problems debugging your handler? Try the Callback Handler Test Tool.

The handler described here processes callbacks from the GrabzIt screenshot web service. The URL of this handler is passed to GrabzIt in the callBackUrl parameter of the save method. However this technique will only work if the handler is accessible via the Internet.

The following parameters are passed to the handler as GET parameters.

  • id - the unique identifier of the screenshot, used by the get_result method
  • filename - the filename of the screenshot, automatically created by combining the screenshot's unique identifier with it's file extension
  • message - any message due to an error caused during the processing of the screenshot
  • customId - any custom id that was passed to the GrabzIt web service via the save method
  • format - the format of the screenshot, e.g "bmp8", "bmp16", "bmp24", "bmp", "csv", "gif", "jpg", "json", "pdf", "png", "tiff" or "xlsx"

If you want to block all access to the handler, except from GrabzIt then use this security technique.

Example

Remember this callback will not work if your application is located on localhost.

This example shows how a GrabzIt Node.js handler can be implemented using express. This captures five parameters passed to it from the GrabzIt service, including the unique id of the screenshot which is passed to the get_result method.

This method then returns the screenshot, which is saved in the screenshot directory.

var express = require('express');
var url = require('url');
var file = require('fs');
var grabzit = require('grabzit');

var app = express();

app.get('/handler', function (req, res) {
    var queryData = url.parse(req.url, true).query;

    var message = queryData.message;
    var customid = queryData.customid;
    var id = queryData.id;
    var filename = queryData.filename;
    var format = queryData.format;

    var client = new grabzit('Sign in to view your Application Key', 'Sign in to view your Application Secret');

    client.get_result(id, function(err, result){
        if (err != null) {            
            return;
        }

        file.writeFile(path.join('public', path.join('results', filename)), result, 'binary');
    });

    res.end();
});
Try all our premium features for free with a 7 day free trial. Then from $5.99 a month, unless cancelled.
  • More Captures
  • More Features
  • More API's
  • Bigger Scrapes
  • Bigger Captures
  • Bigger Everything
Start Free Trial