OSS文件位置配置错误
This commit is contained in:
@@ -24,12 +24,13 @@ public class OSSServer {
|
||||
private String endpoint;
|
||||
@Value("${oss.bucket:null}")
|
||||
private String bucket;
|
||||
@Value("${corp.id:null}")
|
||||
private String corpId;
|
||||
|
||||
@Value("${cdn.url:null}")
|
||||
private String cdnUrl;
|
||||
|
||||
@Value("${oss.file.dir:null}")
|
||||
private String dir;
|
||||
|
||||
/**
|
||||
* 服务端上传文件的方法
|
||||
* ObjectName 为文件存放位置 + 名字,不可包含 bucket
|
||||
@@ -39,7 +40,7 @@ public class OSSServer {
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
try {
|
||||
// 创建PutObjectRequest对象
|
||||
objectName = "partner/" + corpId + "/" + objectName;
|
||||
objectName = dir + objectName;
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, objectName, inputStream);
|
||||
// 创建PutObject请求。
|
||||
ossClient.putObject(putObjectRequest);
|
||||
@@ -77,7 +78,7 @@ public class OSSServer {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try {
|
||||
// ossObject包含文件所在的存储空间名称、文件名称、文件元信息以及一个输入流。
|
||||
OSSObject ossObject = ossClient.getObject(bucket, "partner/" + corpId + "/" + objectName);
|
||||
OSSObject ossObject = ossClient.getObject(bucket, dir + objectName);
|
||||
|
||||
// 读取文件内容转为 ByteArrayInputStream
|
||||
InputStream objectInputstream = ossObject.getObjectContent();
|
||||
@@ -87,7 +88,6 @@ public class OSSServer {
|
||||
outputStream.write(buffer, 0, len);
|
||||
}
|
||||
outputStream.flush();
|
||||
byte[] byteArray = outputStream.toByteArray();
|
||||
|
||||
// ossObject对象使用完毕后必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
|
||||
ossObject.close();
|
||||
|
||||
Reference in New Issue
Block a user