|
@@ -173,7 +173,7 @@ public class AliossTemplateRe implements OssTemplateRe {
|
|
try {
|
|
try {
|
|
this.makeBucket(bucketName);
|
|
this.makeBucket(bucketName);
|
|
String originalName = key;
|
|
String originalName = key;
|
|
- key = this.getFileName(key);
|
|
|
|
|
|
+ //key = this.getFileName(key);
|
|
if(key.indexOf("/")>=0){
|
|
if(key.indexOf("/")>=0){
|
|
originalName = key.substring(key.lastIndexOf("/")+1 , key.length());
|
|
originalName = key.substring(key.lastIndexOf("/")+1 , key.length());
|
|
}else{
|
|
}else{
|
|
@@ -318,58 +318,60 @@ public class AliossTemplateRe implements OssTemplateRe {
|
|
return initResult;
|
|
return initResult;
|
|
}
|
|
}
|
|
|
|
|
|
- public BladeFile putFileWithPath(String fileName, String filePath,Long projectId, InputStream stream) {
|
|
|
|
- try {
|
|
|
|
-
|
|
|
|
- String suffix = "";
|
|
|
|
- int indexOfDot = fileName.lastIndexOf('.');
|
|
|
|
- if (indexOfDot > 0) {
|
|
|
|
- suffix = fileName.substring(indexOfDot + 1);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- String ossUrl = "";
|
|
|
|
- // 判断容器是否存在,不存在就创建
|
|
|
|
- String bucket=getBucketName();
|
|
|
|
- if (!ossClient.doesBucketExist(bucket)) {
|
|
|
|
- ossClient.createBucket(bucket);
|
|
|
|
- CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucket);
|
|
|
|
- createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);
|
|
|
|
- ossClient.createBucket(createBucketRequest);
|
|
|
|
- }
|
|
|
|
- // 设置文件路径和名称
|
|
|
|
- //判断是否为存储成 upload/20230322/xxxx.pdf 还是指定目录 aaaa/bbbb.pdf
|
|
|
|
- if (StringUtils.isEmpty(filePath)) {
|
|
|
|
- Date now = new Date();
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
|
- String formattedDate = sdf.format(now);
|
|
|
|
- filePath = OssConstant.NORMAL_DIRECTORY + "/" + formattedDate;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //如果有项目ID,则存为 项目id/.... ,否则直接在最外层, 临时目录除外
|
|
|
|
- if (!filePath.equals(OssConstant.TEMP_DIRECTORY)) {
|
|
|
|
- if (projectId != null ) {
|
|
|
|
- filePath = projectId + "/" + filePath;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- String fileUrl = filePath + "/" + fileName;
|
|
|
|
- ObjectMetadata objectMetadata = new ObjectMetadata();
|
|
|
|
- objectMetadata.setContentType(getcontentType(suffix));
|
|
|
|
- ossUrl = getOssHost() + fileUrl;
|
|
|
|
-
|
|
|
|
- // 上传文件
|
|
|
|
- PutObjectResult result = ossClient.putObject(new PutObjectRequest(bucket, fileUrl, stream,objectMetadata));
|
|
|
|
-
|
|
|
|
- BladeFile file = new BladeFile();
|
|
|
|
- file.setOriginalName(fileName);
|
|
|
|
- file.setName(fileName);
|
|
|
|
- file.setDomain(this.getOssHost(bucket));
|
|
|
|
- file.setLink(ossUrl);
|
|
|
|
- return file;
|
|
|
|
- } catch (Throwable var9) {
|
|
|
|
- throw var9;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ //不使用
|
|
|
|
+// public BladeFile putFileWithPath(String fileName, String filePath,Long projectId, InputStream stream) {
|
|
|
|
+//
|
|
|
|
+// try {
|
|
|
|
+//
|
|
|
|
+// String suffix = "";
|
|
|
|
+// int indexOfDot = fileName.lastIndexOf('.');
|
|
|
|
+// if (indexOfDot > 0) {
|
|
|
|
+// suffix = fileName.substring(indexOfDot + 1);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// String ossUrl = "";
|
|
|
|
+// // 判断容器是否存在,不存在就创建
|
|
|
|
+// String bucket=getBucketName();
|
|
|
|
+// if (!ossClient.doesBucketExist(bucket)) {
|
|
|
|
+// ossClient.createBucket(bucket);
|
|
|
|
+// CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucket);
|
|
|
|
+// createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);
|
|
|
|
+// ossClient.createBucket(createBucketRequest);
|
|
|
|
+// }
|
|
|
|
+// // 设置文件路径和名称
|
|
|
|
+// //判断是否为存储成 upload/20230322/xxxx.pdf 还是指定目录 aaaa/bbbb.pdf
|
|
|
|
+// if (StringUtils.isEmpty(filePath)) {
|
|
|
|
+// Date now = new Date();
|
|
|
|
+// SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
|
+// String formattedDate = sdf.format(now);
|
|
|
|
+// filePath = OssConstant.NORMAL_DIRECTORY + "/" + formattedDate;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// //如果有项目ID,则存为 项目id/.... ,否则直接在最外层, 临时目录除外
|
|
|
|
+// if (!filePath.equals(OssConstant.TEMP_DIRECTORY)) {
|
|
|
|
+// if (projectId != null ) {
|
|
|
|
+// filePath = projectId + "/" + filePath;
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// String fileUrl = filePath + "/" + fileName;
|
|
|
|
+// ObjectMetadata objectMetadata = new ObjectMetadata();
|
|
|
|
+// objectMetadata.setContentType(getcontentType(suffix));
|
|
|
|
+// ossUrl = getOssHost() + fileUrl;
|
|
|
|
+//
|
|
|
|
+// // 上传文件
|
|
|
|
+// PutObjectResult result = ossClient.putObject(new PutObjectRequest(bucket, fileUrl, stream,objectMetadata));
|
|
|
|
+//
|
|
|
|
+// BladeFile file = new BladeFile();
|
|
|
|
+// file.setOriginalName(fileName);
|
|
|
|
+// file.setName(fileName);
|
|
|
|
+// file.setDomain(this.getOssHost(bucket));
|
|
|
|
+// file.setLink(ossUrl);
|
|
|
|
+// return file;
|
|
|
|
+// } catch (Throwable var9) {
|
|
|
|
+// throw var9;
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
|
|
|
|
|
|
//判断文件的格式
|
|
//判断文件的格式
|