1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "pathToImageUrls": "images",
12 "fileNameFunction": ({url, md5}) => md5(url),
13 "uploadTo": "zip-file",
14 "preDownloadFunction": `/* Example: We get rid of the items with price 0
15 ({ data }) => data.filter((item) => item.price > 0)
16 */`,
17 "postDownloadFunction": `/* Example: We remove items without any successfully uploaded images.
18 We also remove any image URLs that were not uploaded
19
20 ({ data, state }) => {
21 return data.reduce((newData, item) => {
22 const downloadedImages = item.images.filter((imageUrl) => {
23 return state[imageUrl] && state[imageUrl].imageUploaded;
24 });
25
26 if (downloadedImages.length === 0) {
27 return newData;
28 }
29
30 return newData.concat({ ...item, images: downloadedImages });
31 }, []);
32 }
33 */`,
34 "imageCheckType": "content-type",
35 "proxyConfiguration": {
36 "useApifyProxy": true
37 }
38};
39
40
41const run = await client.actor("lukaskrivka/images-download-upload").call(input);
42
43
44console.log('Results from dataset');
45console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
46const { items } = await client.dataset(run.defaultDatasetId).listItems();
47items.forEach((item) => {
48 console.dir(item);
49});
50
51