This project consists of a Node.js script that fetches data from the UNHCR Kobo API, extracts images from the response, and downloads them locally.
- Node.js
- Axios library for HTTP requests
- A configuration file
config.json
with the authentication token
Create a file named config.json
in the root directory of the project with the following structure:
{
"AUTH_TOKEN": "your-authentication-token-here"
}
Replace your-authentication-token-here with your actual authentication token.
- Clone the repository or download the files to your local machine.
- Navigate to the project directory.
- Run npm install to install the required dependencies.
- Ensure that the configuration file is properly set up with the correct authentication token.
- Run node script.js (or the name you've given to the script file) from the command line in the project directory.
- Fetches data from the specified API URL.
- Filters the attachments in the response to only include those with a mimetype of image/jpeg.
- Builds the download links for the images using the filenames.
- Downloads the images and saves them locally.
- If the API request fails, an error message is logged to the console.
- If an image fails to download, an error message specific to that image is logged to the console.
npm install axios
node downloadImages.js
This project is licensed under the terms of the MIT license.