Previous
Conditional sync
When you configure the data management service, Viam automatically uploads data from the default directory ~/.viam/capture
and any directory you configured.
If you want to upload data from another directory or source, you can also:
Typically, you configure the data management service to capture and sync data from your machine at regular intervals. However, you can also use the data management service to sync data from a folder. This can be a dataset you wish to upload once or data that is periodically written to a folder on your system.
If you do not want the data deleted from your machine, copy the data to a new folder and sync that folder instead so that your local copy remains.
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 Component or service.
Select the data management
service and click Create.
On the data management panel, you can see the configuration options.
You can leave the default data sync interval of 0.1
minutes to sync every 6 seconds.
Configure sync from the additional folder
In the Additional paths, enter the full path to the directory with the data you want to upload, for example, /Users/Artoo/my_cat_photos
.
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 before saving your configuration.
Toggle Syncing to on (green) if it isn’t already on.
Click Save in the top right corner of the page.
Confirm that your data uploaded
Navigate to your DATA page and confirm that your data appears there. If you don’t see your files yet, wait a few moments and refresh the page.
You can use the Data Client API to upload files to the Viam Cloud.
Unlike when using the data management service, using the FileUploadFromPath
method uploads the files even if they already exist in the cloud.
In other words, it duplicates data if you run it multiple times.
Also unlike data sync, this method does not delete data from your device.
Get API key
Go to your organization’s setting page and create an API key for a machine part, machine, location, or organization.
Upload a file from a path
Use the FileUploadFromPath
method to upload a file.
You must provide a machine part ID to associate data with.
To upload just one file, make a call to file_upload_from_path
:
import asyncio
import os
from viam.rpc.dial import DialOptions, Credentials
from viam.app.viam_client import ViamClient
# Configuration constants – replace with your actual values
API_KEY = "" # API key, find or create in your organization settings
API_KEY_ID = "" # API key ID, find or create in your organization settings
ORG_ID = "" # Organization ID, find or create in your organization settings
PART_ID = "" # Part ID of machine part that should be associated with the data
FILE_PATH = "file.txt" # Path to the file to upload
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():
viam_client = await connect()
data_client = viam_client.data_client
binary_data_id = await data_client.file_upload_from_path(
# The ID of the machine part the file should be associated with
part_id=PART_ID,
# Any tags you want to apply to this file
tags=["uploaded"],
# Path to the file
filepath=FILE_PATH
)
viam_client.close()
if __name__ == '__main__':
asyncio.run(main())
package main
import (
"context"
"os"
"go.viam.com/rdk/app"
"go.viam.com/rdk/logging"
)
// Configuration constants – replace with your actual values
var (
API_KEY = "" // API key, find or create in your organization settings
API_KEY_ID = "" // API key ID, find or create in your organization settings
ORG_ID = "" // Organization ID, find or create in your organization settings
PART_ID = "" // Part ID of machine part that should be associated with the data
FILE_PATH = "file.txt" // Path to the file to upload
)
func main() {
logger := logging.NewDebugLogger("client")
ctx := context.Background()
viamClient, err := app.CreateViamClientWithAPIKey(
ctx, app.Options{}, API_KEY, API_KEY_ID, logger)
if err != nil {
logger.Fatal(err)
}
defer viamClient.Close()
dataClient := viamClient.DataClient()
binaryDataID, err := dataClient.FileUploadFromPath(
ctx,
PART_ID,
FILE_PATH,
&app.FileUploadOptions{
Tags: []string{"uploaded"},
},
)
if err != nil {
logger.Fatal(err)
}
}
Run your code
Save and run your code once. Running your code more than once will duplicate the data.
Confirm that your data uploaded
Navigate to your DATA page and confirm that your data appears there.
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.
Navigate to your machine
In the Viam mobile app, select an organization by clicking on the menu icon in the top left corner.
Tap the Locations tab and select a location, then select the machine you want your data to be associated with.
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.
If you uploaded a dataset for machine learning, continue to create a dataset.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!