最近更新时间:2022-07-25
在执行任何和UOS服务相关请求前都需要先生成一个Client对象。
// 1.初始化用户身份信息 String accessKey = "AKXXXXXX"; String secretKey = "SKXXXXXX"; BasicAWSCredentials cred = new BasicAWSCredentials(accessKey, secretKey); // 2. 配置client ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProtocol(Protocol.HTTPS); // 3. 设置地域信息 以北京为例,其它地域请按实际情况填写 String endpoint = "oss-cn-north-2.unicloudsrv.com" String region = "北京节点域名"; EndpointConfiguration endpoint = new EndpointConfiguration(endpoint,region); // 4. 生成client AmazonS3 s3 = AmazonS3ClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(cred)) .withClientConfiguration(clientConfiguration) .withEndpointConfiguration(endpoint) .build(); |