Mirth Community

Mirth Community (http://www.mirthcorp.com/community/forums/index.php)
-   General Discussion (http://www.mirthcorp.com/community/forums/forumdisplay.php?f=7)
-   -   AWS S3 Get Javascript Reader (http://www.mirthcorp.com/community/forums/showthread.php?t=219022)

nhunter 03-19-2019 05:33 AM

AWS S3 Get Javascript Reader
 
Hey guys, here is some quick code to retreive a file from an S3 bucket and inside of your Javascript reader. If you have any improvements feel free to share

Code:

// Set the AWS account Access Key, AWS account Secret Key
var awsCreds = new Packages.com.amazonaws.auth.BasicAWSCredentials(accessKey, secretKey);

// Set the s3client
var s3client = new Packages.com.amazonaws.services.s3.AmazonS3Client(awsCreds);

// Create s3Object
var s3Object = s3client.getObject(bucketName, keyName);

var s3ObjectInputStream = s3Object.getObjectContent();

var bReader = new BufferedReader(new InputStreamReader(s3ObjectInputStream));
var line;
var lines = bReader.lines().filter({
        test: function (x) {
                return x.length != 0
        }
}).toArray();

for (var i = 0; i < lines.length; i++) {
        logger.info('Text Line: ' + lines[i]);
        messages.add(new RawMessage(lines[i]));
}
s3ObjectInputStream.close();
return messages;


giogiannola 03-28-2019 08:33 AM

Great!! Thanks!


All times are GMT -8. The time now is 11:53 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation