Read data from Azure Blob Storage using Mirth
- azure-core-1.48.0.jar
- azure-core-http-netty-1.14.2.jar
- azure-identity-1.12.0.jar
- azure-json-1.1.0.jar
- azure-storage-blob-12.25.3.jar
- azure-storage-common-12.24.3.jar
- azure-xml-1.0.0.jar
- jackson-annotations-2.13.5.jar
- jackson-core.2.13.5.jar
- jackson-databind-2.13.5.jar
- jackson-dataformat-xml-2.13.5.jar
- jackson-datatype-jsr310-2.13.5.jar
- netty-handler-4.1.101.Final.jar
- netty-handler-proxy-4.1.101.Final.jar
- netty-resolver-4.1.101.Final.jar
- netty-resolver-dns-4.1.101.Final.jar
To read the file content from the azure blob storage use the below code in mirth
// Put your default connection string protocol here
var string = “DefaultEndpointsProtocol=…”;
var containerName = $cfg(‘SOURCE_CONTAINER’);
var containerClient = new com.azure.storage.blob.BlobServiceClientBuilder().connectionString(string).buildClient().getBlobContainerClient(containerName);
var blobItems = containerClient.listBlobs();
var iterator = blobItems.iterator();
var bufferValue = 1024;
while(iterator.hasNext()){
var blobItem = iterator.next();
var blobClient= containerClient.getBlobClient(blobItem.getName());
var outputStream = new java.io.ByteArrayOutputStream();
channelMap.put(‘fileName’,blobItem.getName());
try{
var inStream = blobClient.openInputStream();
var bytesRead;
var buffer = java.lang.reflect.Array.newInstance(java.lang.Byte .TYPE, bufferValue);
while((bytesRead = inStream.read(buffer))!=-1){
outputStream.write(buffer, 0, bytesRead);
}
var fileContent = new java.lang.String(outputStream.toByteArray(), java.nio.charset.StandardCharsets.UTF_8);
// print the filecontent and see if it extracts it exactly as uploaded in the storage explorer
}catch(Exception){
logger.debug(“exception “+Exception);
}
}