修改 AliyunOssConfig 访问key、访问secret字段名称,方便和其他几种 文件服务器统一

pull/84/head
duandazhi 4 years ago
parent 30558aa7e1
commit b863b079d9

@ -20,8 +20,8 @@ public class AliyunOssConfig {
/** /**
* aliyun oss * aliyun oss
* ACCESS_KEY_SECRET * ACCESS_KEY_SECRET
* AccessKeyId eg:LTAI4GFov2QymkmPf9cXdH5z * AccessKeyId secretKeyeg:LTAI4GFov2QymkmPf9cXdH5z
* AccessKeySecret eg:ap8nmIvD1TctcCLsADS4JbkOoXOluW * AccessKeySecret secretKey eg:ap8nmIvD1TctcCLsADS4JbkOoXOluW
* BucketName eg:yuebaoxiao * BucketName eg:yuebaoxiao
* Endpoint eg:oss-cn-shenzhen.aliyuncs.com * Endpoint eg:oss-cn-shenzhen.aliyuncs.com
* *
@ -29,8 +29,8 @@ public class AliyunOssConfig {
* *
* *
*/ */
private String accessKeyId = ""; private String accessKey = "";
private String accessKeySecret = ""; private String secretKey = "";
private String bucketName = ""; private String bucketName = "";
private String endpoint = ""; private String endpoint = "";
/** /**
@ -45,20 +45,20 @@ public class AliyunOssConfig {
*/ */
private String domain = null; private String domain = null;
public String getAccessKeyId() { public String getAccessKey() {
return accessKeyId; return accessKey;
} }
public void setAccessKeyId(String accessKeyId) { public void setAccessKey(String accessKey) {
this.accessKeyId = accessKeyId; this.accessKey = accessKey;
} }
public String getAccessKeySecret() { public String getSecretKey() {
return accessKeySecret; return secretKey;
} }
public void setAccessKeySecret(String accessKeySecret) { public void setSecretKey(String secretKey) {
this.accessKeySecret = accessKeySecret; this.secretKey = secretKey;
} }
public String getBucketName() { public String getBucketName() {

@ -10,7 +10,6 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -112,7 +111,7 @@ public class AliyunOssDsfServiceImpl implements IDfsService {
/* /*
* Constructs a client instance with your account for accessing OSS * Constructs a client instance with your account for accessing OSS
*/ */
OSS client = new OSSClientBuilder().build(aliyunOssConfig.getEndpoint(), aliyunOssConfig.getAccessKeyId(), aliyunOssConfig.getAccessKeySecret()); OSS client = new OSSClientBuilder().build(aliyunOssConfig.getEndpoint(), aliyunOssConfig.getAccessKey(), aliyunOssConfig.getSecretKey());
String storePath = getStorePath(fileUrl); String storePath = getStorePath(fileUrl);
List<String> keys = new ArrayList<>(); List<String> keys = new ArrayList<>();
keys.add(storePath); keys.add(storePath);
@ -190,7 +189,7 @@ public class AliyunOssDsfServiceImpl implements IDfsService {
* demo https://github.com/aliyun/aliyun-oss-java-sdk/blob/master/src/samples/UploadSample.java * demo https://github.com/aliyun/aliyun-oss-java-sdk/blob/master/src/samples/UploadSample.java
*/ */
private String ossUploadFileSmall(String endpoint, String picturePath, MultipartFile file) throws IOException { private String ossUploadFileSmall(String endpoint, String picturePath, MultipartFile file) throws IOException {
OSS ossClient = new OSSClientBuilder().build(endpoint, aliyunOssConfig.getAccessKeyId(), aliyunOssConfig.getAccessKeySecret()); OSS ossClient = new OSSClientBuilder().build(endpoint, aliyunOssConfig.getAccessKey(), aliyunOssConfig.getSecretKey());
try { try {
// 上传文件 (上传文件流的形式) // 上传文件 (上传文件流的形式)
PutObjectResult putResult = ossClient.putObject(aliyunOssConfig.getBucketName(), picturePath, file.getInputStream()); PutObjectResult putResult = ossClient.putObject(aliyunOssConfig.getBucketName(), picturePath, file.getInputStream());
@ -271,7 +270,7 @@ public class AliyunOssDsfServiceImpl implements IDfsService {
*/ */
ClientBuilderConfiguration conf = new ClientBuilderConfiguration(); ClientBuilderConfiguration conf = new ClientBuilderConfiguration();
conf.setIdleConnectionTime(1000); conf.setIdleConnectionTime(1000);
OSS client = new OSSClientBuilder().build(endpoint, aliyunOssConfig.getAccessKeyId(), aliyunOssConfig.getAccessKeySecret(), conf); OSS client = new OSSClientBuilder().build(endpoint, aliyunOssConfig.getAccessKey(), aliyunOssConfig.getSecretKey(), conf);
try { try {
/* /*
@ -485,7 +484,7 @@ public class AliyunOssDsfServiceImpl implements IDfsService {
@Override @Override
public String objectsCapacityStr() { public String objectsCapacityStr() {
OSS client = new OSSClientBuilder().build(aliyunOssConfig.getEndpoint(), aliyunOssConfig.getAccessKeyId(), aliyunOssConfig.getAccessKeySecret()); OSS client = new OSSClientBuilder().build(aliyunOssConfig.getEndpoint(), aliyunOssConfig.getAccessKey(), aliyunOssConfig.getSecretKey());
final int maxKeys = 200; final int maxKeys = 200;
String nextMarker = null; String nextMarker = null;
ObjectListing objectListing; ObjectListing objectListing;
@ -545,7 +544,7 @@ public class AliyunOssDsfServiceImpl implements IDfsService {
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
// 忽略 // 忽略
} }
OSS ossClient = new OSSClientBuilder().build(aliyunOssConfig.getEndpoint(), aliyunOssConfig.getAccessKeyId(), aliyunOssConfig.getAccessKeySecret()); OSS ossClient = new OSSClientBuilder().build(aliyunOssConfig.getEndpoint(), aliyunOssConfig.getAccessKey(), aliyunOssConfig.getSecretKey());
// 设置URL过期时间为12小时最大值就是43200 // 设置URL过期时间为12小时最大值就是43200
Date expiration = new Date(System.currentTimeMillis() + (43200 * 1000)); Date expiration = new Date(System.currentTimeMillis() + (43200 * 1000));
// 生成以GET方法访问的签名URL访客可以直接通过浏览器访问相关内容。 // 生成以GET方法访问的签名URL访客可以直接通过浏览器访问相关内容。

Loading…
Cancel
Save