(Any Website): File Download

(Any Website): File Download
Downloads a file and adds to file-type data. The GET request to the URL is thrown and the response is saved as a file.
https://support.questetra.com/addons/any-website-file-download/
2019-03-22 (C) Questetra, Inc. (MIT License)
Configs
  • C1: File URL * #{EL}
  • C2: Data Item to add the file (File) *
  • C3: Downloaded File Name * #{EL}
Script
//// == Config Retrieving / 工程コンフィグの参照 ==
let fileUrl = configs.get( "conf_DataIdA" ) + "";
const dataIdB = configs.get( "conf_DataIdB" ) + "";
const saveAs  = configs.get( "conf_SaveAs" ) + "";
// convert 'java.lang.String' to 'javascript string'


//// == Data Retrieving / ワークフローデータの参照 ==
if ( ! fileUrl.startsWith('http') ) {
  throw "Invalid URL. URL must start with either http or https.";
}
//let UrlforName = decodeURI(fileUrl);

let processFiles = engine.findDataByNumber( dataIdB );
// java.util.ArrayList <com.questetra.bpms.core.event.scripttask.QfileView>
if (processFiles === null) {
  processFiles = new java.util.ArrayList();
}

//// == Calculating / 演算 ==
/// File Name (from URI Path with Regular Expression)
let fileName = "";
if( saveAs === "" ){
  throw "Downloaded File Name isn't set";
}else{
  fileName = saveAs;
}

/// Access to the URL
let httpRequest = httpClient.begin(); // HttpRequestWrapper
// com.questetra.bpms.core.event.scripttask.HttpClientWrapper
const response = httpRequest.get( fileUrl ); // HttpResponseWrapper
const httpStatus  = response.getStatusCode() + "";
const responseTxt = response.getResponseAsString();
if (httpStatus >= 300) {
  const error = "Failed to download \n STATUS:" + httpStatus + "\n" + responseTxt;
  throw error;
}
engine.log( "STATUS: " + httpStatus );
const qfile = new com.questetra.bpms.core.event.scripttask.NewQfile(
    fileName, response.getContentType(), response.getResponse()
  );

/// Error Handling
// (no action)


//// == Data Updating / ワークフローデータへの代入 ==
processFiles.add( qfile );
engine.setDataByNumber( dataIdB, processFiles );

Download

Capture

2 thoughts on “(Any Website): File Download”

  1. Pingback: HTTP Files Retrieve – Questetra Support

  2. Pingback: File-Type – Questetra Support

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: