Dataset Image Downloader & Uploader avatar
Dataset Image Downloader & Uploader
Try for free

No credit card required

View all Actors
Dataset Image Downloader & Uploader

Dataset Image Downloader & Uploader

lukaskrivka/images-download-upload
Try for free

No credit card required

Download image files from image URLs in your datasets and save them to a Zip file, Key-Value store, or directly your AWS S3 bucket.

The code examples below show how to run the Actor and get its results. To run the code, you need to have an Apify account. Replace <YOUR_API_TOKEN> in the code with your API token, which you can find under Settings > Integrations in Apify Console. Learn more

1from apify_client import ApifyClient
2
3# Initialize the ApifyClient with your Apify API token
4client = ApifyClient("<YOUR_API_TOKEN>")
5
6# Prepare the Actor input
7run_input = {
8    "pathToImageUrls": "images",
9    "fileNameFunction": "({url, md5}) => md5(url)",
10    "uploadTo": "zip-file",
11    "preDownloadFunction": """/* Example: We get rid of the items with price 0
12({ data }) => data.filter((item) => item.price > 0)
13*/""",
14    "postDownloadFunction": """/* Example: We remove items without any successfully uploaded images.
15 We also remove any image URLs that were not uploaded
16 
17 ({ data, state }) => {
18    return data.reduce((newData, item) => {
19        const downloadedImages = item.images.filter((imageUrl) => {
20            return state[imageUrl] && state[imageUrl].imageUploaded;
21        });
22        
23        if (downloadedImages.length === 0) {
24            return newData;
25        }
26        
27        return newData.concat({ ...item, images: downloadedImages });
28    }, []);
29}
30*/""",
31    "imageCheckType": "content-type",
32    "proxyConfiguration": { "useApifyProxy": True },
33}
34
35# Run the Actor and wait for it to finish
36run = client.actor("lukaskrivka/images-download-upload").call(run_input=run_input)
37
38# Fetch and print Actor results from the run's dataset (if there are any)
39print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
40for item in client.dataset(run["defaultDatasetId"]).iterate_items():
41    print(item)
42
43# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start
Developer
Maintained by Apify
Actor metrics
  • 26 monthly users
  • 10 stars
  • 99.5% runs succeeded
  • 8.8 days response time
  • Created in Nov 2018
  • Modified about 1 month ago