AWS S3 file transfer interface

If you are using Amazon S3 for file storage, you can use the S3 file transfer interface in formulas in Infor Public Sector to upload and download files.

First, use the File Transfers > Amazon S3 node in the FileManagement configuration to connect to S3. You must specify your profile name, access key, and secret access key.

You can then use the interface in formulas. The S3 file transfer interface (Hansen.Core.FileTransfers.IAmazonS3FileTransfer) supports these methods:

Method Description Parameters
Upload Sends a file to S3.
  • key (string): Relative S3 key to upload the file to.
  • stream (System.IO.Stream): A stream representing the file contents
Upload Sends a file to S3.
  • key (string): Relative S3 key to upload the file to.
  • stream (System.IO.Stream): A stream representing the file contents
  • metadata (IDictionary<string, string>): Optional metadata to include with the file in S3
Download Retrieves a file from S3.
  • key (string): Relative S3 key to download the file from

Returns System.IO.Stream: A stream representing the file contents.

GetMetadata Retrieves the metadata for a file in S3.
  • key (string): Relative S3 key of the file.

Returns IDictionary<string, string>: The metadata associated with the file in S3

Exist Determines if a file exists in S3.
  • key (string): Relative S3 key of the file.

Returns boolean: True/False

Delete Deletes a file in S3
  • key (string): Relative S3 key of the file
GetFiles Retrieves a list of files for a specified path in S3.
  • prefix (string): Relative path + prefix representing an area in S3
GetFiles Retrieves a list of files for a specified path in S3.
  • prefix (string): Relative path + prefix representing an area in S3
  • nextMarker (string): Indicates where to continue from when returning a list of files in S3. Used for paging.
Copy Copies a file from one location in S3 to another.
  • sourceKey (string): Relative S3 key of the file to be copied
  • destinationBucket (string): S3 bucket that the file will be copied to
  • destinationKey (string): S3 key that the file will be copied to. The destination bucket and destination key are both required.

Examples

This sample formula shows how to upload a file:

Dim filePath As String = "Custom\\test.pdf"
Dim authProfile As String = "myauthprofile"
Dim fileService As New FileExplorerService
 
Dim fileTransferService As Hansen.Core.FileTransfers.IFileTransferService = 
  ServerApplication.Resolve(Of Hansen.Core.FileTransfers.IFileTransferService)

Dim s3FileTransfer As Hansen.Core.FileTransfers.IAmazonS3FileTransfer =
  fileTransferService.GetFileTransfer(Of Hansen.Core.FileTransfers.IAmazonS3FileTransfer)
  (Hansen.Core.FileTransfers.FileTransferBuiltInType.AmazonS3, authProfile)
 
Dim newFilename As String = "test_" & DateTime.Now.ToString("yyyyMMdd_HHmmssfff") & ".pdf"
 
Using fileStream As IO.Stream = fileService.OpenRead(filePath)
    s3FileTransfer.Upload(newFilename, fileStream)
End Using

This sample formula shows how to download a file:

Dim fileService As New FileExplorerService
 
Dim fileTransferService As Hansen.Core.FileTransfers.IFileTransferService = 
  ServerApplication.Resolve(Of Hansen.Core.FileTransfers.IFileTransferService)

Dim s3FileTransfer As Hansen.Core.FileTransfers.IAmazonS3FileTransfer =
  fileTransferService.GetFileTransfer(Of Hansen.Core.FileTransfers.IAmazonS3FileTransfer)
  (Hansen.Core.FileTransfers.FileTransferBuiltInType.AmazonS3, "myauthprofile")

Dim newFilename As String = "test_" & DateTime.Now.ToString("yyyyMMdd_HHmmssfff") & ".pdf"
Dim outputPath As String = "Custom\\" & newFilename
 
Using s3Stream As IO.Stream = s3FileTransfer.Download(newFilename)
    Using fileStream As IO.Stream = fileService.OpenWrite(outputPath)
        s3Stream.CopyTo(fileStream)
    End Using
End Using

This sample formula shows how to delete a file:

Dim fileService As New FileExplorerService
 
Dim fileTransferService As Hansen.Core.FileTransfers.IFileTransferService = 
  ServerApplication.Resolve(Of Hansen.Core.FileTransfers.IFileTransferService)

Dim s3FileTransfer As Hansen.Core.FileTransfers.IAmazonS3FileTransfer =
  fileTransferService.GetFileTransfer(Of Hansen.Core.FileTransfers.IAmazonS3FileTransfer)
  (Hansen.Core.FileTransfers.FileTransferBuiltInType.AmazonS3, "myauthprofile")

Dim newFilename As String = "test_" & DateTime.Now.ToString("yyyyMMdd_HHmmssfff") & ".pdf"

s3FileTransfer.Delete(newFilename)

This sample formula shows how to return a list of files:

Dim fileService As New FileExplorerService
 
Dim fileTransferService As Hansen.Core.FileTransfers.IFileTransferService = 
  ServerApplication.Resolve(Of Hansen.Core.FileTransfers.IFileTransferService)

Dim s3FileTransfer As Hansen.Core.FileTransfers.IAmazonS3FileTransfer =
  fileTransferService.GetFileTransfer(Of Hansen.Core.FileTransfers.IAmazonS3FileTransfer)
  (Hansen.Core.FileTransfers.FileTransferBuiltInType.AmazonS3, "myauthprofile")

Dim response = s3FileTransfer.GetFiles("test_")
 
For Each file In response.Files
    ServerApplication.LogEntry("Test", ResultSeverity.Info, "Getting file " & file.Key)
Next

This sample formula shows how to determine if a file exists:

Dim fileService As New FileExplorerService
 
Dim fileTransferService As Hansen.Core.FileTransfers.IFileTransferService = 
  ServerApplication.Resolve(Of Hansen.Core.FileTransfers.IFileTransferService)
Dim s3FileTransfer As Hansen.Core.FileTransfers.IAmazonS3FileTransfer =
  fileTransferService.GetFileTransfer(Of Hansen.Core.FileTransfers.IAmazonS3FileTransfer)
  (Hansen.Core.FileTransfers.FileTransferBuiltInType.AmazonS3, "myauthprofile")

Dim fileName = "\\file\location\fileName.ext"
 
Dim response = s3FileTransfer.Exist(file_path)
 
Dim result = fileName & " " & If(response, "File exists.", "File does not exist.")
 
ServerApplication.LogEntry("Test", ResultSeverity.Info, result)

This sample formula shows how to copy a file from one location to another:

Dim fileService As New FileExplorerService

Dim fileTransferService As Hansen.Core.FileTransfers.IFileTransferService = 
  ServerApplication.Resolve(Of Hansen.Core.FileTransfers.IFileTransferService)

Dim s3FileTransfer As Hansen.Core.FileTransfers.IAmazonS3FileTransfer =
  fileTransferService.GetFileTransfer(Of Hansen.Core.FileTransfers.IAmazonS3FileTransfer)
  (Hansen.Core.FileTransfers.FileTransferBuiltInType.AmazonS3, "myauthprofile")

Dim source_Key = "BillingBatchProcessLogDownload.txt"
Dim destination_bucket = "infor-devops-dev-ips"
Dim destination_Key = "hps113304.filestransfer/files.test/CopyBillingBatchProcessLogDownload.txt"

'Check if the file existed in the source location
Dim response = s3FileTransfer.Exist(source_Key)

'If the file exists, then continue to copy and write a log
If response Then
    s3FileTransfer.Copy(source_Key, destination_bucket, destination_Key)
    ServerApplication.LogEntry("Test File Copy", ResultSeverity.Info, source_Key & " " & 
    " File has been successfully copied to the location: " & destination_Key)
Else
    'If the file doesn't exist, then write a log to inform the user               
    ServerApplication.LogEntry("Test File Copy", ResultSeverity.Info, source_Key & " " & 
    " File does not exist.")
End If

GetMetaData

Dim fileService As New FileExplorerService

Dim fileTransferService As Hansen.Core.FileTransfers.IFileTransferService = 
  ServerApplication.Resolve(Of Hansen.Core.FileTransfers.IFileTransferService)

Dim s3FileTransfer As Hansen.Core.FileTransfers.IAmazonS3FileTransfer = 
  fileTransferService.GetFileTransfer(Of Hansen.Core.FileTransfers.IAmazonS3FileTransfer)
  (Hansen.Core.FileTransfers.FileTransferBuiltInType.AmazonS3, "myauthprofile")
 
Dim source_Key = "BillingBatchProcessLogDownload.txt"
 
'Check if the file exists in the source location
Dim response = s3FileTransfer.Exist(source_Key)
 
'If the file exists, then continue to get the metadata
If response Then
 
Dim metaData As IDictionary(Of String, String) = New Dictionary(Of String, String)
 
'Write the property name and value in the NGEvent log
ServerApplication.LogEntry("Getting metadata of file: " & source_Key)

'Note that GetMetadata only captures user-defined metadata

metaData = s3FileTransfer.GetMetadata(source_Key)
ServerApplication.LogEntry("Metadata Count is " & metaData.Count)
 
For Each meta In metaData
    ServerApplication.LogEntry("Property Name: " & meta.Key)
    ServerApplication.LogEntry("Property Value: " & meta.Value)
Next
 
Else
    'If the file doesn't exist, add a log entry to inform the user
    ServerApplication.LogEntry(source_Key & " " & " File does not exist.")
End If