upload_files_cloud

imerit_ango.sdk.SDK.

upload_files_cloud(project_id, assets, storage_id, batches)

Import files in cloud storage to Ango Hub. Check Importing Assets for more information.

Parameters

  • project_id: string

  • assets: List[string]

    • A list of asset dictionaries in the [{"data": <URL>, "externalId": "<external_id>"}] format.

    • Assets uploaded with this method can also contain attachments, batches, metadata, and contextData.

Example
public_file = [
    {
        "data": "https://angohub-public-assets.s3.eu-central-1.amazonaws.com/CzXTtJV.jpg",
        "externalId": "aws-public.png",
        "metadata": {
            "width": 1500,
            "height": 1800
        },
        "contextData": {
            "key1": "value1"
        },
        "batches": ["Batch 1", "Batch 2"]
        "attachments": [
            {'type': "IMAGE", 'value': "https://angohub-public-assets.s3.eu-central-1.amazonaws.com/CzXTtJV.jpg"},
            {'type': "TEXT", 'value': "An attachment."}]
    }
]

For image and video attachments, you may provide links to assets in private buckets, provided that you've connected them to Ango Hub. More information on how to do so can be found on the Attachments page.

For Markdown assets, you may directly include the Markdown file as plain text in the data field, like so:

import os
from dotenv import load_dotenv
from imerit_ango.sdk import SDK

load_dotenv('variables.env')
api_key = os.getenv('API_KEY')
project_id = os.getenv('PROJECT_ID')

ango_sdk = SDK(api_key)

markdown_text = '
<div style="margin:10px;display:flex;">
    <div style="width:50%">
        <div style="font-size:13px;font-weight:500;display:flex;">
            <div style="width:100px;color:gray">Hello World!</div>
        </div>
    </div>
</div>'

external_id = "100001.md"
batch_name = "Batch-1"

file_paths = []
file_paths.append({"data": markdown_text, "externalId": external_id, "batches": [batch_name]})

response = sdk.upload_files_cloud(project_id=project_id, assets=file_paths)

Batches you specify in the assets dictionary will override the batches you specify in the batches parameter of this function.

  • storage_id: string, Optional, default None

  • batches: List[string], Optional, default None

    • You may add the files being uploaded to one or multiple batches, by passing a list of batch IDs. You may obtain a list of batch IDs available in your project using get_batches function, or create new ones using create_batch function.

Returns:

  • output: dict

Examples

Importing a file from a public bucket, and assigning it to a batch:

import os
from dotenv import load_dotenv
from imerit_ango.sdk import SDK

load_dotenv('variables.env')
api_key = os.getenv('API_KEY')
project_id = os.getenv('PROJECT_ID')

ango_sdk = SDK(api_key)

batch_id_list = ['<YOUR BATCH ID>']

public_file = [{"data": "https://storage.googleapis.com/a-public-bucket/file.png",
                "externalId": "myExternalId.png"}]

ango_sdk.upload_files_cloud(project_id=project_id, assets=public_file, batches=batch_id_list)

Importing a file from a private bucket, and assigning it to multiple batches:

import os
from dotenv import load_dotenv
from imerit_ango.sdk import SDK

load_dotenv('variables.env')
api_key = os.getenv('API_KEY')
project_id = os.getenv('PROJECT_ID')

ango_sdk = SDK(api_key)

batch_id_list = ['<BATCH ID 1>', '<BATCH ID 2>']
storage_id = '<YOUR_STORAGE_ID>' # Obtain with get_storages, mandatory when importing files from private buckets

private_file = [{"data": "https://storage.googleapis.com/a-private-bucket/file.png",
                 "externalId": "myExternalId.png"}]

ango_sdk.upload_files_cloud(project_id=project_id,
                            assets=public_file,
                            batches=batch_id_list,
                            storage_id=storage_id)

Last updated