-
Notifications
You must be signed in to change notification settings - Fork 110
/
upload_data_capture_file.go
44 lines (37 loc) · 1.06 KB
/
upload_data_capture_file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package datasync
import (
"context"
v1 "go.viam.com/api/app/datasync/v1"
"go.viam.com/rdk/services/datamanager/datacapture"
)
func uploadDataCaptureFile(ctx context.Context, client v1.DataSyncServiceClient, f *datacapture.File, partID string) error {
md := f.ReadMetadata()
sensorData, err := datacapture.SensorDataFromFile(f)
if err != nil {
return err
}
// Do not attempt to upload a file without any sensor readings.
if len(sensorData) == 0 {
return nil
}
ur := &v1.DataCaptureUploadRequest{
Metadata: &v1.UploadMetadata{
PartId: partID,
ComponentType: md.GetComponentType(),
ComponentName: md.GetComponentName(),
ComponentModel: md.GetComponentModel(),
MethodName: md.GetMethodName(),
Type: md.GetType(),
MethodParameters: md.GetMethodParameters(),
FileExtension: md.GetFileExtension(),
Tags: md.GetTags(),
SessionId: md.GetSessionId(),
},
SensorContents: sensorData,
}
_, err = client.DataCaptureUpload(ctx, ur)
if err != nil {
return err
}
return nil
}