Feature example: File upload avatar
Feature example: File upload

Under maintenance

Pricing

Pay per usage

Go to Store
Feature example: File upload

Feature example: File upload

Under maintenance

Developed by

Apify

Apify

Maintained by Community

The Actor showcases the fileupload input. See the input schema specification at https://docs.apify.com/platform/actors/development/actor-definition/input-schema/specification/v1 for details.

0.0 (0)

Pricing

Pay per usage

0

Total users

1

Monthly users

1

Runs succeeded

>99%

Last modified

5 days ago

.actor/actor.json

{
"actorSpecification": 1,
"name": "feature-example-file-upload",
"title": "Feature Example: File Upload",
"description": "Show the File Upload input",
"version": "0.0",
"input": "./input_schema.json",
"dockerfile": "../Dockerfile"
}

.actor/input_schema.json

{
"title": "Scrape data from a web page",
"type": "object",
"schemaVersion": 1,
"properties": {
"fileUrl": {
"title": "URL of the file that should be processed",
"type": "string",
"description": "Under the hood, it's still just a string",
"editor": "fileupload"
}
},
"required": ["fileUrl"]
}

src/main.js

1import { Actor, log } from 'apify';
2import axios from 'axios';
3
4await Actor.init();
5
6// The fileupload input is just a friendlier UI for string.
7// That's what the Actor recieves.
8const { fileUrl } = await Actor.getInput();
9
10log.info('Got file url on the input', { fileUrl });
11
12// Treating the string as hopefully url of some file is up to the code.
13log.info('Using HEAD request with axios to get the content type...');
14const response = await axios.head(fileUrl);
15
16log.info(`Based on the response headers, the file is ${response.headers['content-type']}`);
17log.info(`And has ${response.headers['content-length']} Bytes`);
18
19await Actor.exit();

.dockerignore

# configurations
.idea
# crawlee and apify storage folders
apify_storage
crawlee_storage
storage
# installed files
node_modules
# git folder
.git

.gitignore

# This file tells Git which files shouldn't be added to source control
.DS_Store
.idea
.zed
dist
node_modules
apify_storage
storage/*
!storage/key_value_stores
storage/key_value_stores/*
!storage/key_value_stores/default
storage/key_value_stores/default/*
!storage/key_value_stores/default/INPUT.json

Dockerfile

# Specify the base Docker image. You can read more about
# the available images at https://docs.apify.com/sdk/js/docs/guides/docker-images
# You can also use any other image from Docker Hub.
FROM apify/actor-node:22
# Check preinstalled packages
RUN npm ls crawlee apify puppeteer playwright
# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
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 --omit=dev --omit=optional \
&& echo "Installed NPM packages:" \
&& (npm list --omit=dev --all || true) \
&& echo "Node.js version:" \
&& node --version \
&& echo "NPM version:" \
&& npm --version \
&& rm -r ~/.npm
# Next, copy the remaining files and directories with the source code.
# Since we do this after NPM install, quick build will be really fast
# for most source file changes.
COPY . ./
# Create and run as a non-root user.
RUN adduser -h /home/apify -D apify && \
chown -R apify:apify ./
USER apify
# Run the image.
CMD npm start --silent

package.json

{
"name": "feature-example-file-upload",
"version": "0.0.1",
"type": "module",
"description": "This is an example of an Apify Actor.",
"engines": {
"node": ">=18.0.0"
},
"dependencies": {
"apify": "^3.2.6",
"axios": "^1.5.0"
},
"scripts": {
"start": "node ./src/main.js",
"test": "echo \"Error: oops, the Actor has no tests yet, sad!\" && exit 1"
},
"author": "It's not you it's me",
"license": "ISC"
}