Commit f9e4f9f4 by 钟明宏

增加测试代码

parent cf70e879
......@@ -6,10 +6,13 @@ import com.qcloud.cos.exception.CosServiceException;
import com.qcloud.cos.model.Bucket;
import com.qcloud.cos.model.CannedAccessControlList;
import com.qcloud.cos.model.CreateBucketRequest;
import com.qcloud.cos.model.PutObjectResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Test;
import java.io.File;
/**
* @author zhongminghong
* @email zhongmh@yunmaozj.com
......@@ -22,24 +25,41 @@ public class COSClientTest {
public void createBucket() {
COSClient cosClient = CosFactory.buildDefaultClient();
String bucket = "HelloWorld-1301823233" ;
log.info("创建桶的名称:{}",bucket);
String bucket = "HelloWorld-1301823233";
log.info("创建桶的名称:{}", bucket);
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucket);
// 设置 bucket 的权限为 Private(私有读写), 其他可选有公有读私有写, 公有读写
createBucketRequest.setCannedAcl(CannedAccessControlList.Private);
try {
Bucket bucketResult = cosClient.createBucket(createBucketRequest);
log.info("{}",bucketResult);
log.info("{}", bucketResult);
} catch (CosServiceException serverException) {
serverException.printStackTrace();
} catch (CosClientException clientException) {
clientException.printStackTrace();
}finally {
} finally {
deleteBucket(bucket);
}
}
private void deleteBucket(String bucket){
@Test
public void uploadFile() {
COSClient cosClient = CosFactory.buildDefaultClient();
String bucket = "world-1301823233";
log.info("创建桶的名称:{}", bucket);
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucket);
// 设置 bucket 的权限为 Private(私有读写), 其他可选有公有读私有写, 公有读写
createBucketRequest.setCannedAcl(CannedAccessControlList.PublicRead);
PutObjectResult putObjectResult = cosClient.putObject(bucket, "20190621093008.jpg", new File("C:\\Users\\Administrator\\Pictures\\TIM图片20190621093008.jpg"));
System.out.println(putObjectResult.getContentMd5());
System.out.println(putObjectResult.getDateStr());
System.out.println(putObjectResult.getExpirationTime());
System.out.println(putObjectResult.getVersionId());
}
private void deleteBucket(String bucket) {
COSClient cosClient = CosFactory.buildDefaultClient();
cosClient.deleteBucket(bucket);
}
......
......@@ -5,6 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<modules>
<module>cos-api</module>
<module>fastdfs</module>
</modules>
<parent>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment