How to Upload a file to S3 Bucket on AWS using JAVA


This is the simple method to upload a file in S3 Bucket. It could be public or private

1. pom.xml dependency
go to mvnrepository website and search for "aws-java-sdk-s3". Find version 1.11.424 and copy pom dependency and put it on pom.xml file

               
com.amazonaws
aws-java-sdk-s3
1.11.424

2. these are the imported from dependency jars to make sure you have not choose wrong one in case
Imports:
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;


3. Details Required
Please ask administrator responsible for AWS. ask for accessKey and SecretKey
Ask for S3 Bucket folder if not ask him to create a S3 Bucket folder where you can upload the file


4. Java Code to upload file on to S3 Bucket
UploadToS3Bucket uploadToAWS = new UploadToS3Bucket();
AWSCredentials credentials = new BasicAWSCredentials(accessKey ,
SecretKey);

AmazonS3 s3client = AmazonS3ClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion(Regions.AP_SOUTHEAST_2) .build(); s3client.putObject("test-automation-bucket-folder-name", "fileNameInString", new File("path of the File in String"));

Comments

Popular posts from this blog

Inspect iOS app using Appium Inspector

Android Native element functions / classes Appium