Files
You can upload and download files to and from the Catalytic platform. You can then reference those files in Fields in Pushbots and Instances.
The Files
client allows you to upload and download files from the Catalytic platform, and to get file metadata like size, content-type and filename. It provides the following methods:
Method | Description |
---|---|
Get GetAsync | Gets metadata of a File by Id |
Download DownloadAsync | Downloads a File by Id |
GetFileStream GetFileStreamAsync | Gets a readable stream of a File by Id |
Upload UploadAsync | Uploads one or more new Files |
Quickstart Example
/*
* This example demonstrates downloading and uploading files
* from a Workflow Instance.
*/
using Catalytic.Sdk;
using Catalytic.Sdk.Entities;
using System;
using System.IO;
namespace Catalytic.Sdk.Examples
{
class Program
{
// update this to your email before running this sample
public const string YourEmail = "[email protected]";
static void Main(string[] args)
{
// Create and initialize the Catalytic SDK Client
var catalytic = new Client(Credentials.Default);
// Find workflows matching "Sdk Example Workflows"
var matches = catalytic.Workflows.Find(
Where.Text.Matches("Sdk Example Workflow"));
// `matches` is a results page containing `Workflows` and
// a `NextPageToken` you can use to page through results.
// We only expect one match for this example so we can simply
// get the first matching Workflow.
var workflow = matches.Workflows.FirstOrDefault();
if (workflow == null)
{
workflow = catalytic.Workflows.Import(
new Uri("https://push.bot/sdk-example"));
}
// Now that we've got our workflow, let's set the inputs it expects
var request = workflow
.SetInput("Age", 42)
.SetInput("Name", "Alice")
.SetName($"SDK Example - {DateTimeOffset.Now.ToString()}");
// Start the workflow
var instance = catalytic.Instances.Start(request);
// Get the step we want to complete
var steps = catalytic.Instances.GetSteps(instance.InstanceId).Steps;
var uploadStep = steps.Where(
s => s.Name == "Upload Updated Spreadsheet and Set Email").First();
// Download the Data Table from the "Table" field as a CSV
var tableId = instance.Fields["Table"].GetValue<Guid>();
var csvFile = catalytic.DataTables.Download(tableId, DataTableExportFormat.CSV);
// Do our "business logic" to transform the csv data
// As a simple example, we replace "Foo" with "Bar"
var updatedCsvContent = csvFile.OpenText().ReadToEnd().Replace("Foo", "Bar");
// Create the output csv file locally
var updatedCsvFile = new FileInfo(Path.GetTempFileName());
File.WriteAllText(updatedCsvFile.FullName, updatedCsvContent);
// To complete the step, we will set both a text and a file field
var stepRequest = step
.SetInput("Updated CSV", updatedCsvFile)
.SetInput("Email Address", YourEmail);
catalytic.Instances.CompleteStep(stepRequest);
Console.WriteLine($"You should have an email waiting for you at {YourEmail} now with the updated CSV converted to an Excel attachment");
}
}
}
Updated about 3 years ago