Read file from RPA server and save it to S3, export link


#1

Sampe bellow can run on RPA server Groovy script, read file and save it to s3 folder.


List files on Windows shared folder
#2
<?xml version="1.0" encoding="UTF-8"?>
<config>

	<var-def name="test_node_id">
		<template>${test_node_id}</template>
	</var-def>

	<var-def name="file_name">
		<template>${file_name}</template>
	</var-def>

	<script><![CDATA[
	
		import com.thoughtworks.selenium.*;
		import org.openqa.selenium.*;
	
		import java.io.ByteArrayInputStream;
		import java.io.File;
		import java.io.FileOutputStream;
		import java.io.InputStream;
		import java.nio.file.Files;
		import java.nio.file.Path;
		import java.nio.file.Paths;
		import org.apache.commons.codec.binary.Base64;
		import org.apache.commons.io.IOUtils;

		Integer ELEMENT_TIMEOUT = 15;
		Integer PAGE_TIMEOUT = 40;
		Integer SMART_WAIT = 60;

		byte[] entryPasisingData = null;

		public byte[] readDataFromFile(String fileName){
				byte[] byteArray = null;
				String byteString = (String) autoitDriver.executeScript(
				"byte[] result=java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(\"C:/Users/\"+System.getProperty(\"user.name\")+\"/Downloads/"
				+ fileName + "\"));\n"
				+ "byte[] encoded=org.apache.commons.codec.binary.Base64.encodeBase64(result);\n"
				+ "return new String(encoded);",
				new String[] {	"GROOVY"	});
				byteArray = Base64.decodeBase64(byteString.getBytes());
				return byteArray;
		}
	]]></script>


	<selenium-flow>
		<selenium name="aDriver" browser="autoit"	close-on-completion="true" start-in-private="false" node-id="${test_node_id}">
			<script><![CDATA[
					autoitDriver = aDriver.getWrappedObject();
					Thread.sleep(2000);
					entryPasisingData = readDataFromFile(file_name.toString().trim());
			]]></script>
		</selenium>
	</selenium-flow>

	<var-def name="file_url">
		<s3 bucket="screenshots">
			<s3-put path="s3_file_older/${file_name}" content-type="application/octet-stream" content-disposition="inline" acl="PublicRead">
				<script return='entryPasisingData' />
			</s3-put>
		</s3>
	</var-def>

	<export include-original-data="false">
		<single-column name="file_url" value="${file_url}" />
	</export>
</config>

#3

It will open file from C:\users\user_name_profile\Downloads folder. Please put the file into this folder only. node_id property can help to specify particular RPA node id to lauch and view this sample.