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