This workflow is a simple demonstration of working with file uploads using a workflow input form.
Aria Automation Orchestrator 8.18
The attached workflow uses a "Scriptable Task" with a very simple script, and an Input form to provide a means to upload, store, read and delete a file.
.package) attached to this article.Samples directory, or by searching for its name, "File Upload".Workflow Schema:
Input form:
Example Output:
md5sum net.broadcom.samples.fileupload.package
c6d9d77df1facf9a1de2b83f385ea131
Content of Script Task for reference:
// GLOBAL VARIABLES
// Variable definitions
var fileName = fileUpload.name;
var fileContent = fileUpload.content;
var localFilePath = System.getTempDirectory();
// HELPER FUNCTIONS
// Write uploaded file content into a local temp file
function storeFile(srcFilePath, fileContent) {
System.log("Writing to '"+srcFilePath+"' ...")
var fileObj = new FileWriter(srcFilePath);
try {
// Open the temp file
fileObj.open();
// Clear the local file contents
fileObj.clean();
// Write the new content to the local file
fileObj.write(fileContent);
} catch (e) {
System.error("Error: " + e)
} finally {
if (fileObj) {
// Close the temp file
fileObj.close();
}
}
}
// Read the contents of a local file
function readFile(fName) {
System.log("Reading content of: '" + fName + "' ...");
var fileObj = new FileReader(fName);
try {
// Open the file from temp file
fileObj.open();
if (fileObj.exists) {
fileContent = fileObj.readAll();
System.log("Contents of '"+fName+"':\n"+fileContent);
} else {
System.warn("File '" + fName + "' not found!");
}
} catch (e) {
System.error("Error: " + e)
} finally {
if (fileObj) {
// Close the local file
fileObj.close();
}
}
}
// Delete a local file
function deleteFile(fName) {
System.log("Deleting '" + fName + "' ...")
var fileObj = new File(fName);
try {
// Check if the file exists
if (fileObj.exists) {
fileObj.deleteFile();
} else {
System.warn("File '" + fName + "' not found!");
}
} catch (e) {
System.error("Error: " + e)
}
}
// START
System.log("Uploaded file name: '" + fileName + "'");
System.log("Uploaded file content:\n" + fileContent);
System.log("Local temp directory: " + localFilePath);
// Write to local file
storeFile(localFilePath + "/" + fileName, fileContent);
// Read from local file
readFile(localFilePath + "/" + fileName);
// Delete local file
deleteFile(localFilePath + "/" + fileName);
// END