Read/Download Object From S3 Using S3 Connector In Mule 4
In this tutorial we will demonstrate how can we read/download object from S3 using S3 connector in mule 4, we will use the below operations to upload and download the file
Create object: This operation used to upload an object to S3 and it supports input streams,files,strings and byte array
Create object presigned uri: This operation is used to access the object from S3 bucket using pre signed URL, this is useful to share the URL with other users so that they can access the object without login in to AWS console, there is limitation that this URL will be valid for certain period of time.
Note: The maximum expiration time for presigned url is one week from time of creation. So there is no way to have a presigned url without expiry time. It depends on how you generate the S3 pre-signed URL.
Ref: https://aws.amazon.com/premiumsupport/knowledge-center/presigned-url-s3-bucket-expiration/
TestData
[{ "CUSTOMER_ID":1, "CUSTOMER_NAME":"TEST1", "ADDRESS1":"Flat 101", "ADDRESS2":"Viman Nagar", "POSTALCODE":"201018", "CITY":"PUNE" },{ "CUSTOMER_ID":2, "CUSTOMER_NAME":"TEST2", "ADDRESS1":"Flat 102", "ADDRESS2":"Viman Nagar 1", "POSTALCODE":"201019", "CITY":"PUNE" },{ "CUSTOMER_ID":3, "CUSTOMER_NAME":"TEST3", "ADDRESS1":"Flat 103", "ADDRESS2":"Viman Nagar", "POSTALCODE":"201018", "CITY":"PUNE" },{ "CUSTOMER_ID":4, "CUSTOMER_NAME":"TEST4", "ADDRESS1":"Flat 104", "ADDRESS2":"Viman Nagar 4", "POSTALCODE":"201019", "CITY":"PUNE" }]
First we will create the CSV file using create object operation and test data mentioned above and then read/download the csv file using create object presigned uri
Create project in anypoint studio and configure the listener to trigger the request
Convert the JSON object to CSV Format
Drag and drop the create object operation from mule palette and configure the Bucket name, File name and object to create the csv file
Set the variable as timestamp and set the data which is valid for next 7 days
Drag and drop create object presigned uri and configure the Bucket name, File name and Expiration time and Select method as GET
Create the transform message to send the S3 URL as Json
We can see S3 url created as below
{
}
Open the S3 URL in browser and we can see CSV file downloaded successfully
Sample application: ReadFileFromS3 Sample project
how to download all type of extension files that are there in s3 bucket using mule 4? while using plain get object connector not able to download all files.