• Builds
  • latest 0.0.57 / 2018-05-30
  • Created 2018-05-29
  • Last modified 2018-09-18
  • grade 1


This act takes the URLs prepared by a crawler and downloads the images to finally zip them


To run the actor, send a HTTP POST request to:<YOUR_API_TOKEN>

The POST payload will be passed as input for the actor. For more information, read the docs.

Example input

Content type: application/json; charset=utf-8

{ "_id": "YOUR_CRAWLER_RUN_ID" }

Source code

Based on the apify/actor-node-basic Docker image (see docs).

// Get all the libraries this crawler uses
const Apify = require('apify');
const _ = require('underscore');
const rp = require('request-promise');
const Promise = require('bluebird');

Apify.main(async () => {
    // Get act input and validate it
    const input = await Apify.getValue('INPUT');
    if (!input || !input._id) {
        throw new Error('Input is missing the "_id" attribute. Did you start it from crawler finish webhook?');
    const executionId = input._id;
    // Print info about crawler run
    const crawlerRunDetails = await Apify.client.crawlers.getExecutionDetails({ executionId });
    if (!crawlerRunDetails) {
        throw new Error(`There is no crawler run with ID: "${executionId}"`);
    console.log(`Details of the crawler run (ID: ${executionId}):`);
    // Iterate through all crawler results and count them
    // Here is the place where you can add something more adventurous :)
    console.log(`Counting results from crawler run...`);
    const limit = 100;
    let offset = 0;
    let totalItems = 0;
    let results;

    results = await Apify.client.crawlers.getExecutionResults({ 
    // Prepare each result for downloading
    await Promise.each(results.items[0].pageFunctionResult, async function(value, i){
           console.log('url', value.url)
           // Move each result in the key-value store
           const file = await rp ({
               url : value.url, encoding : null
           // Attach the right filename and encoding
           await Apify.setValue(value.file+'.png', file, { contentType : 'image/png'})
    // Take the key-value store and zip data (this uses a different Actor (
    const run = await'jaroslavhejlek/zip-key-value-store', { "keyValueStoreId": process.env.APIFY_DEFAULT_KEY_VALUE_STORE_ID, "filesPerZipFile": 2000 });