File Library
Introduction
Functions to work with blobs / files.
Allowing to create resources to import files from configured storages as well as creation of resources to facilitate file upload from the users machine.
This library exposes rather high level functions working with ImportFileHandle
encoding user intent to import a file from a pl-wide
configured storage or to upload file from users side in a universal string representation.
Sources
https://github.com/milaboratory/platforma/blob/main/sdk/workflow-tengo/src/file.lib.tengo
API
Import
file := import("@platforma-sdk/workflow-tengo:file")
importFile
Imports an external file into the workflow, either from pre-configured storage, available from the pl instance, or from the client machine via upload.
Arguments:
importFileHandle:string- a string file import handle, in most cases obtained via the LS controller in UI
Return:
result:{file: field, handle: field}- a structure with 2 fields. A handle needs to be passed to model through outputs, and a file is the result file that will be imported.
Example:
// import file
fImport := file.importFile(args.importFileHandleArgument)
// save file import handle for progress
outputs.importHandle = fImport.handle
// saving exports
exports.file = fImport.file
exportFile
Given a reference to the file, converts it into resource that can be downloaded from the UI side.
Arguments:
blob:either resource or field- a blob resource that the one wants to save.
Return:
savedBlob:field- a reference to the saved blob that can be passed di.
Example:
The example is a workflow that runs a simple command, saves a file and exports it to the output. For API of exec library see this page.
exec := import("@platforma-sdk/workflow-tengo:exec")
file := import("@platforma-sdk/workflow-tengo:file")
wf := import("@platforma-sdk/workflow-tengo:workflow")
wf.body(func(args) {
command := exec.builder().
cmd("/bin/bash").
arg("-c")
arg("echo 42 > output.txt").
saveFile("output.txt").
run()
return {
outputs: {
fileOutput: file.exportFile(command.getFile("output.txt"))
},
exports: {}
}
}