Upload a batch of data

If you configured cloud sync, Viam automatically uploads data from the specified directory to the cloud, at the interval you specified. However, if you want to upload a batch of data once from somewhere else, either from a different directory on your machine or from your personal computer or mobile device, you have several options using the Viam app, the data client API, or the Viam mobile app.

Sync a batch of data from another directory

Typically, you configure the data service to sync data from your machine at regular intervals indefinitely. However, if you already have a cache of data you’d like to use with Viam, you can temporarily modify your configuration to sync a batch of data and then revert your config changes after the data is uploaded.

Prerequisites

A running machine connected to the Viam app. Click to see instructions.
Add a new machine in the Viam app. Then follow the setup instructions to install viam-server or viam-micro-server on the device you’re using for your project and connect to the Viam app. Wait until your machine has successfully connected.
Enable data capture and sync on your machine.

Add the data management service:

On your machine’s CONFIGURE tab, click the + icon next to your machine part in the left-hand menu and select Service.

Select the data management / RDK service and click Create. You can leave the default data sync interval of 0.1 minutes to sync every 6 seconds.

Instructions

Folder

1. Organize your data

Put the data you want to sync in a directory on your machine. All of the data in the folder will be synced, so be sure that you want to upload all of the contents of the folder.

2. Configure sync from the additional folder

In the Additional paths, enter the full path to the directory where the data you want to upload is stored, for example, /Users/Artoo/my_cat_photos.

Toggle Syncing to on (green) if it isn’t already on.

Data service configured in the Viam app as described.

Click Save in the top right corner of the page.

3. Confirm that your data uploaded

Navigate to your DATA page in the Viam app and confirm that your data appears there. If you don’t see your files yet, wait a few moments and refresh the page.

4. Remove the folder path

Once the data has uploaded, navigate back to your data service config. You can now delete the additional path you added. You can also turn off Syncing unless you have other directories you’d like to continue to sync from.

Upload data with Python

You can use the Python data client API file_upload_from_path method to upload one or more files from your computer to the Viam cloud.

Prerequisites

Install the Viam Python SDK

Install the Viam Python SDK by running the following command on the computer from which you want to upload data:

pip install viam-sdk

Instructions

1. Get API key

Go to your organization’s setting page and create an API key for your individual machine part, machine, location, or organization.

2. Add a file_upload_from_path API call

Create a Python script and use the file_upload_from_path method to upload your data, depending on whether you are uploading one or multiple files:

To upload just one file, make a call to file_upload_from_path.

Click this to see example code
import asyncio

from viam.rpc.dial import DialOptions, Credentials
from viam.app.viam_client import ViamClient


async def connect() -> ViamClient:
    dial_options = DialOptions(
      credentials=Credentials(
        type="api-key",
        # Replace "<API-KEY>" (including brackets) with your machine's API key
        payload='<API-KEY>',
      ),
      # Replace "<API-KEY-ID>" (including brackets) with your machine's
      # API key ID
      auth_entity='<API-KEY-ID>'
    )
    return await ViamClient.create_from_dial_options(dial_options)


async def main():
    # Make a ViamClient
    viam_client = await connect()
    # Instantiate a DataClient to run data client API methods on
    data_client = viam_client.data_client
    await data_client.file_upload_from_path(
      # The ID of the machine part the file should be associated with
      part_id="abcdefg-1234-abcd-5678-987654321xyzabc",
      # Any tags you want to apply to this file
      tags=["cat", "animals", "brown"],
      # Path to the file
      filepath="/Users/Artoo/my_cat_photos/brown-cat-on-a-couch.png"
    )

    viam_client.close()

if __name__ == "__main__":
    asyncio.run(main())

To upload all the files in a directory, you can use the file_upload_from_path method inside a for loop.

Click this to see example code
import asyncio
import os

from viam.rpc.dial import DialOptions, Credentials
from viam.app.viam_client import ViamClient


async def connect() -> ViamClient:
    dial_options = DialOptions(
      credentials=Credentials(
        type="api-key",
        # Replace "<API-KEY>" (including brackets) with your machine's API key
        payload='<API-KEY>',
      ),
      # Replace "<API-KEY-ID>" (including brackets) with your machine's
      # API key ID
      auth_entity='<API-KEY-ID>'
    )
    return await ViamClient.create_from_dial_options(dial_options)


async def main():
    # Make a ViamClient
    viam_client = await connect()
    # Instantiate a DataClient to run data client API methods on
    data_client = viam_client.data_client
    # Specify directory from which to upload data
    my_data_directory = "/Users/Artoo/my_cat_photos"

    for file_name in os.listdir(my_data_directory):
        await data_client.file_upload_from_path(
          part_id="abcdefg-1234-abcd-5678-987654321xyzabc",
          tags=["cat", "animals", "brown"],
          filepath=os.path.join(my_data_directory, file_name)
        )

    viam_client.close()

if __name__ == "__main__":
    asyncio.run(main())
Cloud connection

3. Run your code

Save and run your code once. Running your code more than once will duplicate the data. View your uploaded data in your DATA page in the Viam app.

Upload images with the Viam mobile app

Upload images as machine data straight from your phone, skipping the normal data capture and cloud synchronization process, through the Viam mobile app. This is useful if you want to capture images for training machine learning models on the go.

Prerequisites

Download the Viam mobile app and sign into your Viam account

Install the mobile app from the App Store or Google Play.

apple store icon google play store icon

Instructions

1. Navigate to your machine

In the Viam mobile app, select an organization by clicking on the menu icon in the top left corner and tapping an organization.

Tap the Locations tab and select a location, then select the machine you want your data to be associated with.

2. Upload images

Tap the menu button marked “” in the upper right corner. Tap Upload Images.

Select each image you want to upload, then tap Add.

The uploaded images metadata will contain the machine part you selected. However, the uploaded images will not be associated with a component or method.

Next steps

Now that you have a batch of data uploaded, you can train an ML model on it. Or, if you want to collect and upload data not in a batch, see Capture and Sync Image Data.

Have questions, or want to meet other people working on robots? Join our Community Discord.

If you notice any issues with the documentation, feel free to file an issue or edit this file.