Example Image Download avatar
Example Image Download

Pricing

Pay per usage

Go to Store
Example Image Download

Example Image Download

Developed by

Lukáš Křivka

Lukáš Křivka

Maintained by Community

Download a single image from a URL and store it into a key-value store.

0.0 (0)

Pricing

Pay per usage

4

Total users

159

Monthly users

3

Runs succeeded

89%

Last modified

2 years ago

Dockerfile

# This is a template for a Dockerfile used to run acts in Actor system.
# The base image name below is set during the act build, based on user settings.
# IMPORTANT: The base image must set a correct working directory, such as /usr/src/app or /home/user
FROM apify/actor-node-basic:v0.21.10
# Second, copy just package.json and package-lock.json since it should be
# the only file that affects "npm install" in the next step, to speed up the build
COPY package*.json ./
# Install NPM packages, skip optional and development dependencies to
# keep the image small. Avoid logging too much and print the dependency
# tree for debugging
RUN npm --quiet set progress=false \
&& npm install --only=prod --no-optional \
&& echo "Installed NPM packages:" \
&& (npm list --all || true) \
&& echo "Node.js version:" \
&& node --version \
&& echo "NPM version:" \
&& npm --version
# Copy source code to container
# Do this in the last step, to have fast build if only the source code changed
COPY . ./
# NOTE: The CMD is already defined by the base image.
# Uncomment this for local node inspector debugging:
# CMD [ "node", "--inspect=0.0.0.0:9229", "main.js" ]

package.json

{
"name": "apify-project",
"version": "0.0.1",
"description": "",
"author": "It's not you it's me",
"license": "ISC",
"dependencies": {
"apify": "0.21.10",
"request-promise": "latest"
},
"scripts": {
"start": "node main.js"
}
}

main.js

1const Apify = require('apify');
2const rp = require('request-promise');
3
4Apify.main(async () => {
5 // Get input of your actor
6 const input = await Apify.getInput();
7 console.log('My input:');
8 console.dir(input);
9
10 const {
11 imageUrl,
12 proxy = { useApifyProxy: false },
13 // Optional headers
14 headers = {},
15 } = input;
16
17 // Optional proxy
18 const proxyConfiguration = await Apify.createProxyConfiguration(proxy);
19
20 // encoding: null means that we download raw binary data
21 // which is what we want for an image
22 const imageBuffer = await rp({
23 url: imageUrl,
24 encoding: null,
25 proxy: proxyConfiguration ? proxyConfiguration.newUrl() : null,
26 headers,
27 gzip: true,
28 });
29 console.log(`Image downloaded`)
30 await Apify.setValue('OUTPUT', imageBuffer, { contentType: 'image/png' });
31
32 console.log('Image is saved at:');
33 const storeId = Apify.getEnv().defaultKeyValueStoreId;
34 console.log(`https://api.apify.com/v2/key-value-stores/${storeId}/records/OUTPUT?disableRedirect=true`);
35});