Uploading a Text File via Stream with qie.callRESTWebService().

0 votes
asked May 7 by rich-c-2789 (17,430 points)
Can you show me how to use qie.callRESTWebService() to upload a text file using a stream?

1 Answer

0 votes

This code snippet demonstrates uploading a text file to a URL using a stream:

// Create a new parameter map object using the 'qie' library.
var parameterMap = qie.newParameterMap();

// Define the URL template for uploading a text file to a specific endpoint. This is used to override the endpoint in the web service connection.
var urlTemplate = qie.evaluateTemplate("http://localhost:8083/streamUploadTextFile");

// Open the text file as a stream. Change the file path to match your file's location.
var contentAsStream ="/Users/dir/Documents/System flag.sql");

// Call a REST web service using the provided parameters.
var result = qie.callRESTWebService(

// Store the response from the web service call in a cache for further processing.
messageCache.setValue("restResult", result);

Here's a breakdown of what each part of the code does:

  1. Parameter Map Initialization:

    • Initializes a new parameter map object using the newParameterMap() function from the 'qie' library.  Used to define request headers.
  2. URL Template Definition:

    • Defines the URL template for the target endpoint where the text file will be uploaded using the evaluateTemplate() function from the 'qie' library.
  3. File Stream Opening:

    • Opens the text file specified by its file path as a stream using FileInputStream from the Java standard library. Ensure to replace the file path with the actual path to your text file.
  4. Calling the REST Web Service:

    • Calls a RESTful web service using the callRESTWebService() function from the 'qie' library, passing various parameters:
      • 'wsName': Placeholder for the name of the web service connection.
      • 'urlTemplate': URL template of the endpoint used to override endpoint in web service connection.
      • 'POST': HTTP method used for the request (in this case, POST).
      • 'contentAsStream': Stream containing the content of the text file.
      • 'text/plain': Content type, specifying that the content is plain text.
      • 'parameterMap': Additional parameters or headers passed with the request.
      • '60000': Timeout value for the request in milliseconds (here, set to 60 seconds).
  5. Response Handling:

    • Stores the response from the web service call in a cache named "stream response" for further processing or retrieval.

Make sure to replace placeholders like 'wsName' and the file path with actual values relevant to your use case. Also, ensure that the endpoint URL and method match the requirements of the web service you are interacting with.


See also:

Handling HTTP requests and responses

Making Requests via qie.callRESTWebService()


answered May 7 by rich-c-2789 (17,430 points)
edited May 16 by rich-c-2789