Reputation: 77
We have a flow that sends files from a windows directory to a S3 Bucket. We use Nifi to get files from that bucket and we need to get the owner of the file.
I found "Include File Attributes" in ListFile processor but I can't find an equivalent in the processor ListS3.
Any ideas ?
Thank you
Upvotes: 0
Views: 105
Reputation: 1956
Use below code sample to retrieve the owner details.
import com.amazonaws.services.s3.AmazonS3
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import com.amazonaws.services.s3.model.ObjectMetadata
// Initialize the S3 client
AmazonS3 s3Client = AmazonS3ClientBuilder.defaultClient()
// Fetch the S3 object key from FlowFile attributes
def s3ObjectKey = flowFile.getAttribute('s3.object.key')
// Get the owner of the S3 object
def s3ObjectMetadata = s3Client.getObjectMetadata('your-s3-bucket-name', s3ObjectKey)
def owner = s3ObjectMetadata.getOwner()
// Set the owner as an attribute on the FlowFile
flowFile = session.putAttribute(flowFile, 'file.owner', owner.toString())
return flowFile
Remember to adjust the script and configuration to match your specific requirements, including the S3 bucket name and the attribute names used in your NiFi data flow.
Upvotes: 0