AWS S3 with Presigned URL

0

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 have a url = https://maps.googleapis.com/maps/api/staticmap?center=40.7916869275725,-73.9480028393158&size=300x250&zoom=18&maptype=roadmap&key=AIzaSyCJ5YSmLdEUwclkPi2t29IaY0OrDEnjXsw&style=element:geometry|color:0xf5f5f5&style=element:labels.icon|visibility:off&style=element:labels.text.fill|color:0x616161&style=element:labels.text.stroke|color:0xf5f5f5&style=feature:administrative|visibility:off&style=feature:administrative.land_parcel|visibility:off&style=feature:administrative.land_parcel|color:0xbdbdbd&style=feature:poi|visibility:off&style=feature:poi|color:0xeeeeee&style=feature:poi|color:0x757575&style=feature:poi.park|color:0xe5e5e5&style=feature:poi.park|color:0x9e9e9e&style=feature:road|color:0xffffff&style=feature:road|visibility:off&style=feature:road.arterial|color:0x757575&style=feature:road.highway|color:0xdadada&style=feature:road.highway|color:0x616161&style=feature:road.local|visibility:off&style=feature:road.local|color:0x9e9e9e&style=feature:transit|visibility:off&style=feature:transit.line|color:0xe5e5e5&style=feature:transit.station|color:0xeeeeee&style=feature:water|color:0xc9c9c9&style=feature:water|color:0x9e9e9e&path=color:0x000000FF|fillcolor:0x7f97b2|weight:1|40.7917628547078,-73.9474291163126|40.7912643063267,-73.9477918269511|40.7915942270527,-73.9485737283519|40.7920931444449,-73.9482107549615|40.7917628547078,-73.9474291163126

I need to show this image using java in aws lambdahandler.

It would be great if anyone can help me

java
image
amazon-s3
download
pre-signed-url
asked on Stack Overflow May 10, 2018 by ShaiNe Ram • edited May 10, 2018 by ShaiNe Ram

1 Answer

0

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) )
     }

 }
answered on Stack Overflow May 10, 2018 by Paul Jay

User contributions licensed under CC BY-SA 3.0