具有预签名URL的AWS S3

时间:2018-05-10 11:27:41

标签: java image amazon-s3 download pre-signed-url

我正在为我的项目使用aws。我有一个预先签名的图片网址。我需要将预先签名的图片放入我的s3存储桶中。我怎样才能在使用JAVA的aws中做到这一点。

我有一个网址= 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

我需要在aws lambdahandler中使用java来显示这个图像。

如果有人能帮助我会很棒

1 个答案:

答案 0 :(得分:0)

您可以使用AWS s3 SDK从s3存储桶中放置和获取对象。您需要设置AWS访问权限和密钥凭据。

例如:

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

 }