I am using aws for my project. I have a presigned image url.I need to get the presigned image into my s3 bucket. How can I do this in aws using JAVA.
I need to show this image using java in aws lambdahandler.
It would be great if anyone can help me
You can use the AWS s3 SDK to put and get objects from an s3 bucket. You need to set up AWS access and secret key credentials.
For example :
public AWS{
private String awsAccessKey;
private String awsSecretKey;
private String s3BucketName;
private AmazonS3ClientBuilder builder;
private AmazonS3 s3Client;
public AWS(){
this.awsAccessKey = "yourAccessKey";
this.awsSecretKey = "yourSecretKey"
this.s3BucketName = "yourBucketName";
BasicAWSCredentials awsCreds = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
builder = AmazonS3ClientBuilder
.standard()
.withRegion(YOUR_REGION);
s3Client = builder.withCredentials(new AWSStaticCredentialsProvider(awsCreds)).build();
}
public AmazonS3 getClient(){ return s3Client; }
public String getBucketName(){ return s3BucketName; }
}
public s3ActionClass{
private AWS aws;
public s3ActionClass(AWS aws){
this.aws = aws;
}
public static void putS3Bucket(){
File file = new File("path-to-your-file");
aws.getClient().putObject(aws.getBucketName(), file.getName(), file) )
}
}
User contributions licensed under CC BY-SA 3.0