| | |
| | | import com.heredata.hos.model.PutObjectResult; |
| | | import com.heredata.hos.model.bucket.Bucket; |
| | | import com.heredata.model.VoidResult; |
| | | import com.stylefeng.guns.modular.system.util.SpringContextsUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.io.InputStream; |
| | |
| | | */ |
| | | @Slf4j |
| | | public class NCOSSUtil { |
| | | |
| | | |
| | | private static QianYunTongConfig qianYunTongConfig = SpringContextsUtil.getBean(QianYunTongConfig.class).getQianYunTongConfig();; |
| | | |
| | | /** |
| | | * 创建桶 |
| | | * @param bucketName |
| | |
| | | * accessKey:向UAAS服务请求到的access_key |
| | | * secretKey:向UAAS服务请求到的secret_key |
| | | */ |
| | | HOS hos = new HOSClientBuilder().build(QianYunTongProperties.endPoint, QianYunTongProperties.account, QianYunTongProperties.accessKey, QianYunTongProperties.secretKey); |
| | | HOS hos = new HOSClientBuilder().build(qianYunTongConfig.getEndPoint(), qianYunTongConfig.getAccount(), qianYunTongConfig.getAccessKey(), qianYunTongConfig.getSecretKey()); |
| | | try { |
| | | // 创建请求对象,并且设置创建桶名为"example"的桶 |
| | | CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName); |
| | |
| | | * accessKey:向UAAS服务请求到的access_key |
| | | * secretKey:向UAAS服务请求到的secret_key |
| | | */ |
| | | HOS hos = new HOSClientBuilder().build(QianYunTongProperties.endPoint, QianYunTongProperties.account, QianYunTongProperties.accessKey, QianYunTongProperties.secretKey); |
| | | HOS hos = new HOSClientBuilder().build(qianYunTongConfig.getEndPoint(), qianYunTongConfig.getAccount(), qianYunTongConfig.getAccessKey(), qianYunTongConfig.getSecretKey()); |
| | | try { |
| | | // 查询桶名为"example"的详情 |
| | | Bucket bucket = hos.getBucketInfo(bucketName); |
| | |
| | | * accessKey:向UAAS服务请求到的access_key |
| | | * secretKey:向UAAS服务请求到的secret_key |
| | | */ |
| | | HOS hos = new HOSClientBuilder().build(QianYunTongProperties.endPoint, QianYunTongProperties.account, QianYunTongProperties.accessKey, QianYunTongProperties.secretKey); |
| | | HOS hos = new HOSClientBuilder().build(qianYunTongConfig.getEndPoint(), qianYunTongConfig.getAccount(), qianYunTongConfig.getAccessKey(), qianYunTongConfig.getSecretKey()); |
| | | try { |
| | | VoidResult result = hos.deleteBucket(bucketName); |
| | | if (result.getResponse().isSuccessful()) { |
| | |
| | | * accessKey:向UAAS服务请求到的access_key |
| | | * secretKey:向UAAS服务请求到的secret_key |
| | | */ |
| | | HOS hos = new HOSClientBuilder().build(QianYunTongProperties.endPoint, QianYunTongProperties.account, QianYunTongProperties.accessKey, QianYunTongProperties.secretKey); |
| | | HOS hos = new HOSClientBuilder().build(qianYunTongConfig.getEndPoint(), qianYunTongConfig.getAccount(), qianYunTongConfig.getAccessKey(), qianYunTongConfig.getSecretKey()); |
| | | // 桶策略字符串 |
| | | try { |
| | | VoidResult result = hos.setBucketPolicy(bucketName, policyText); |
| | |
| | | * accessKey:向UAAS服务请求到的access_key |
| | | * secretKey:向UAAS服务请求到的secret_key |
| | | */ |
| | | HOS hos = new HOSClientBuilder().build(QianYunTongProperties.endPoint, QianYunTongProperties.account, QianYunTongProperties.accessKey, QianYunTongProperties.secretKey); |
| | | HOS hos = new HOSClientBuilder().build(qianYunTongConfig.getEndPoint(), qianYunTongConfig.getAccount(), qianYunTongConfig.getAccessKey(), qianYunTongConfig.getSecretKey()); |
| | | try { |
| | | PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key , inputStream); |
| | | PutObjectResult example = hos.putObject(putObjectRequest); |
| | |
| | | * accessKey:向UAAS服务请求到的access_key |
| | | * secretKey:向UAAS服务请求到的secret_key |
| | | */ |
| | | HOS hos = new HOSClientBuilder().build(QianYunTongProperties.endPoint, QianYunTongProperties.account, QianYunTongProperties.accessKey, QianYunTongProperties.secretKey); |
| | | HOS hos = new HOSClientBuilder().build(qianYunTongConfig.getEndPoint(), qianYunTongConfig.getAccount(), qianYunTongConfig.getAccessKey(), qianYunTongConfig.getSecretKey()); |
| | | try { |
| | | HOSObject example = hos.getObject(bucketName, key); |
| | | if (example.getResponse().isSuccessful()) { |
| | |
| | | * accessKey:向UAAS服务请求到的access_key |
| | | * secretKey:向UAAS服务请求到的secret_key |
| | | */ |
| | | HOS hos = new HOSClientBuilder().build(QianYunTongProperties.endPoint, QianYunTongProperties.account, QianYunTongProperties.accessKey, QianYunTongProperties.secretKey); |
| | | HOS hos = new HOSClientBuilder().build(qianYunTongConfig.getEndPoint(), qianYunTongConfig.getAccount(), qianYunTongConfig.getAccessKey(), qianYunTongConfig.getSecretKey()); |
| | | try { |
| | | VoidResult example = hos.deleteObject(bucketName, key); |
| | | if (example.getResponse().isSuccessful()) { |