Download attachments

Download the files attached to the Toloker responses.

Steps to follow

1. Import Toloka-Kit

Connect the Toloka-Kit library to your script.

import toloka.client as toloka

2. Instantiate TolokaClient

Replace the sample API key with your own one.

toloka_client = toloka.
TolokaClient
('PlaceYourRealApiKey_Here', 'PRODUCTION');

3. Download attachment

Find out the ID and the extension of the file attached to the Toloker response which you want to download. Then download this file calling the download_attachment() method.

# Use the standard 'with open()' Python method with the 'wb' (write + binary) parameters specified

with open(attachment_id + '.jpg', 'wb') as attachment_file:

toloka_client.
download_attachment
('fr.5867be74-249b-4264-9ed0-aa5d4c201846', out=attachment_file)

The attachment will be saved to the specified out destination.

Complete code: Download attachments

import toloka.client as toloka
toloka_client = toloka.TolokaClient('PlaceYourRealApiKey_Here', 'PRODUCTION')
with open(attachment_id + '.jpg', 'wb') as attachment_file:
toloka_client.download_attachment('fr.5867be74-249b-4264-9ed0-aa5d4c201846', out=attachment_file)
List of classes and methods used in this recipe

See also

Last updated: February 7, 2023

Toloka-Kit
OverviewGetting API keyQuick start
Recipes
Reference
toloka.client
toloka.async_client
toloka.autoquality [autoquality]
toloka.metrics
toloka.streaming