|
|
@@ -3,15 +3,8 @@ package cn.reghao.oss.sdk;
|
|
|
import cn.reghao.jutil.jdk.converter.ByteHex;
|
|
|
import cn.reghao.jutil.jdk.security.Base64Util;
|
|
|
import cn.reghao.jutil.jdk.security.DigestUtil;
|
|
|
-import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
|
|
-import com.amazonaws.auth.BasicAWSCredentials;
|
|
|
-import com.amazonaws.client.builder.AwsClientBuilder;
|
|
|
import com.amazonaws.services.s3.AmazonS3;
|
|
|
-import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
|
|
-import com.amazonaws.services.s3.model.ObjectMetadata;
|
|
|
-import com.amazonaws.services.s3.model.PutObjectResult;
|
|
|
-import com.amazonaws.services.s3.model.S3Object;
|
|
|
-import com.amazonaws.services.s3.model.S3ObjectInputStream;
|
|
|
+import com.amazonaws.services.s3.model.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
|
|
@@ -24,25 +17,13 @@ import java.security.NoSuchAlgorithmException;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
public class ObjectBasicService {
|
|
|
- private String endpoint;
|
|
|
- private String region;
|
|
|
private final String bucketName;
|
|
|
- private String accessKey;
|
|
|
- private String secretKey;
|
|
|
private final AmazonS3 s3Client;
|
|
|
|
|
|
public ObjectBasicService(String endpoint, String bucketName) {
|
|
|
- this.endpoint = endpoint;
|
|
|
- this.region = "chengdu";
|
|
|
this.bucketName = bucketName;
|
|
|
- this.accessKey = "LTAI5t9juYR3sSP3t7fstqyt";
|
|
|
- this.secretKey = "Tn54Dliyk6ET3nYevum9KGRxrM8Ytt";
|
|
|
- this.s3Client = AmazonS3ClientBuilder.standard()
|
|
|
- .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)))
|
|
|
- .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, region))
|
|
|
- .withPathStyleAccessEnabled(false)
|
|
|
- .withChunkedEncodingDisabled(true)
|
|
|
- .build();
|
|
|
+ S3Client s3Client = new S3Client(endpoint, bucketName);
|
|
|
+ this.s3Client = s3Client.getS3Client();
|
|
|
}
|
|
|
|
|
|
public void putObject(String key, File file) throws NoSuchAlgorithmException {
|
|
|
@@ -125,9 +106,10 @@ public class ObjectBasicService {
|
|
|
File file = new File(filePath);
|
|
|
String key = String.format("aa/bb/cc/%s", file.getName());
|
|
|
key = "video/playback/NbnoDb1qqN";
|
|
|
+ key = "video/playback/ee878672a083434bb465327c75c58681";
|
|
|
//objectBasicService.putObject(key, file);
|
|
|
- objectBasicService.getObject(key, "/home/reghao/Downloads/11111");
|
|
|
- //objectBasicService.headObject(key);
|
|
|
+ //objectBasicService.getObject(key, "/home/reghao/Downloads/11111");
|
|
|
+ objectBasicService.headObject(key);
|
|
|
//objectBasicService.objectExist(key);
|
|
|
log.info("{}/{}", endpoint, key);
|
|
|
}
|