update
This commit is contained in:
@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
@@ -47,9 +48,9 @@ public class OssClientController {
|
||||
public ResponseResult getUploadFileConfig(){
|
||||
// host的格式为 bucketname.endpoint
|
||||
String host = "https://" + bucket + "." + endpoint;
|
||||
|
||||
OSS client = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
OSS client = null;
|
||||
try {
|
||||
client = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
long expireTime = 300;
|
||||
long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
|
||||
Date expiration = new Date(expireEndTime);
|
||||
@@ -65,6 +66,10 @@ public class OssClientController {
|
||||
}catch (Exception e){
|
||||
log.info("exception", e);
|
||||
throw new ServiceException(ErrorCodeEnum.GET_INFO_ERROR);
|
||||
}finally {
|
||||
if(Objects.nonNull(client)){
|
||||
client.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
@@ -45,8 +46,9 @@ public class OssClientController {
|
||||
// host的格式为 bucketname.endpoint
|
||||
String host = "https://" + bucket + "." + endpoint;
|
||||
|
||||
OSS client = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
OSS client = null;
|
||||
try {
|
||||
client = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
long expireTime = 300;
|
||||
long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
|
||||
Date expiration = new Date(expireEndTime);
|
||||
@@ -61,6 +63,10 @@ public class OssClientController {
|
||||
return ResponseResult.success(result);
|
||||
}catch (Exception e){
|
||||
log.info("exception", e);
|
||||
}finally {
|
||||
if(Objects.nonNull(client)){
|
||||
client.shutdown();
|
||||
}
|
||||
}
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user