Uploading and managing files with workflow input forms
search cancel

Uploading and managing files with workflow input forms

book

Article ID: 424365

calendar_today

Updated On:

Products

VCF Operations/Automation (formerly VMware Aria Suite)

Issue/Introduction

This workflow is a simple demonstration of working with file uploads using a workflow input form.

Environment

Aria Automation Orchestrator 8.18

Resolution

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.

Part 1: Importing the File Upload Package

  1. Download the workflow package file (.package) attached to this article.
  2. (Optional) Verify the checksum of the downloaded package to confirm its integrity by following the steps in KB 387116.
  3. (Optional) You may want to remove the older version if you have previously imported it.
  4. Import the package into VMware Aria Orchestrator by following the official documentation: Import a Package.
  5. Once imported, the workflow will be available in the Workflows tab under the Samples directory, or by searching for its name, "File Upload".

Workflow Schema:

 

Part 2: Running the Workflow

  1. Run the "File Upload" workflow. You will be able to browse for a text file to be processed.
  2. After running the workflow, you will see some example output in log section.

Input form:

Example Output:

Additional Information

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

 

Attachments

net.broadcom.samples.fileupload.package get_app