From 3a5d12b67221a19ff199846c19c4e74b71f3be84 Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Sat, 11 Jun 2022 17:15:03 +0800
Subject: [PATCH] 图片,文件上传文件名修改
---
src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java | 33 +++++++++++++++++----------------
1 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java b/src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java
index 97b996a..cd99ea5 100644
--- a/src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java
+++ b/src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java
@@ -211,7 +211,7 @@
minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucket).build());
}
String fileName = file.getOriginalFilename();
- String newName = "upload/picture/" + UUID.randomUUID().toString().replaceAll("-", "")
+ String newName = "upload/picture/f" + UUID.randomUUID().toString().replaceAll("-", "")
+ fileName.substring(fileName.lastIndexOf("."));
InputStream in = file.getInputStream();
String[] split = newName.split("/");
@@ -226,7 +226,7 @@
.headers(headers)
.build());
InputStream inputStream = file.getInputStream();
- FtpUtil.uploadFile(FtpConfig.ftpHost, ftpPort, FtpConfig.ftpUserName, ftpPassword, ftpPath, "/", "f"+split[2], inputStream);
+ FtpUtil.uploadFile(FtpConfig.ftpHost, ftpPort, FtpConfig.ftpUserName, ftpPassword, ftpPath, "/", split[2], inputStream);
in.close();
String urls = "http://61.131.136.25:2081/zhba/" + newName;
//数据封装
@@ -263,7 +263,7 @@
minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucket).build());
}
String fileName = file.getOriginalFilename();
- String newName = "upload/picture/" + UUID.randomUUID().toString().replaceAll("-", "")
+ String newName = "upload/picture/f" + UUID.randomUUID().toString().replaceAll("-", "")
+ fileName.substring(fileName.lastIndexOf("."));
InputStream in = file.getInputStream();
String[] split = newName.split("/");
@@ -278,7 +278,7 @@
.headers(headers)
.build());
InputStream inputStream = file.getInputStream();
- FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/","f"+split[2], inputStream);
+ FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/",split[2], inputStream);
in.close();
String urls = "http://61.131.136.25:2081/zhba/" + newName;
return R.data(urls);
@@ -310,7 +310,7 @@
minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucket).build());
}
String fileName = file.getOriginalFilename();
- String newName = "upload/picture/" + UUID.randomUUID().toString().replaceAll("-", "")
+ String newName = "upload/picture/f" + UUID.randomUUID().toString().replaceAll("-", "")
+ fileName.substring(fileName.lastIndexOf("."));
InputStream in = file.getInputStream();
String[] split = newName.split("/");
@@ -325,7 +325,7 @@
.headers(headers)
.build());
InputStream inputStream = file.getInputStream();
- FtpUtil.uploadFile(FtpConfig.ftpHost, ftpPort, FtpConfig.ftpUserName, ftpPassword, ftpPath, "/", "f"+split[2], inputStream);
+ FtpUtil.uploadFile(FtpConfig.ftpHost, ftpPort, FtpConfig.ftpUserName, ftpPassword, ftpPath, "/", split[2], inputStream);
in.close();
String urls = "http://61.131.136.25:2081/zhba/" + newName;
//数据封装
@@ -405,7 +405,8 @@
}
if(multipartFile.getName().toLowerCase().endsWith(".png") || multipartFile.getName().toLowerCase().endsWith(".jpg")) {
- String newName = "upload/picture/" + UUID.randomUUID().toString().replaceAll("-", "") + multipartFile.getName().substring(multipartFile.getName().lastIndexOf("."));
+ String name = UUID.randomUUID().toString().replaceAll("-", "") + multipartFile.getName().substring(multipartFile.getName().lastIndexOf("."));
+ String newName = "upload/picture/f" + name;
InputStream in = multipartFile.getInputStream();
String[] split = newName.split("/");
//创建头部信息
@@ -444,7 +445,7 @@
//文件推送
InputStream inputStream = multipartFile.getInputStream();
- FtpUtil.uploadFile(FtpConfig.ftpHost, ftpPort, FtpConfig.ftpUserName, ftpPassword, ftpPath, "/", "f"+split[2], inputStream);
+ FtpUtil.uploadFile(FtpConfig.ftpHost, ftpPort, FtpConfig.ftpUserName, ftpPassword, ftpPath, "/", split[2], inputStream);
in.close();
}
}
@@ -532,7 +533,7 @@
}
if(multipartFile.getName().toLowerCase().endsWith(".png") || multipartFile.getName().toLowerCase().endsWith(".jpg")) {
- String newName = "upload/picture/" + UUID.randomUUID().toString().replaceAll("-", "") + multipartFile.getName().substring(multipartFile.getName().lastIndexOf("."));
+ String newName = "upload/picture/f" + UUID.randomUUID().toString().replaceAll("-", "") + multipartFile.getName().substring(multipartFile.getName().lastIndexOf("."));
InputStream in = multipartFile.getInputStream();
String[] split = newName.split("/");
//创建头部信息
@@ -571,7 +572,7 @@
//文件推送
InputStream inputStream = multipartFile.getInputStream();
- FtpUtil.uploadFile(FtpConfig.ftpHost, ftpPort, FtpConfig.ftpUserName, ftpPassword, ftpPath, "/", "f"+split[2], inputStream);
+ FtpUtil.uploadFile(FtpConfig.ftpHost, ftpPort, FtpConfig.ftpUserName, ftpPassword, ftpPath, "/", split[2], inputStream);
in.close();
}else {
pic.set(false);
@@ -653,7 +654,7 @@
fileList = fileUtil.getSubFiles(desPath,fileList);
for (MultipartFile multipartFile : fileList){
if(multipartFile.getName().toLowerCase().endsWith(".png") || multipartFile.getName().toLowerCase().endsWith(".jpg")) {
- String newName = "upload/picture/" + UUID.randomUUID().toString().replaceAll("-", "") + multipartFile.getName().substring(multipartFile.getName().lastIndexOf("."));
+ String newName = "upload/picture/f" + UUID.randomUUID().toString().replaceAll("-", "") + multipartFile.getName().substring(multipartFile.getName().lastIndexOf("."));
InputStream in = multipartFile.getInputStream();
String[] split = newName.split("/");
//创建头部信息
@@ -708,7 +709,7 @@
//文件推送
InputStream inputStream = multipartFile.getInputStream();
- FtpUtil.uploadFile(FtpConfig.ftpHost, ftpPort, FtpConfig.ftpUserName, ftpPassword, ftpPath, "/", "f"+split[2], inputStream);
+ FtpUtil.uploadFile(FtpConfig.ftpHost, ftpPort, FtpConfig.ftpUserName, ftpPassword, ftpPath, "/", split[2], inputStream);
in.close();
}
}
@@ -748,7 +749,7 @@
minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucket).build());
}
String fileName = file.getOriginalFilename();
- String newName = "upload/picture/" + UUID.randomUUID().toString().replaceAll("-", "")
+ String newName = "upload/picture/f" + UUID.randomUUID().toString().replaceAll("-", "")
+ fileName.substring(fileName.lastIndexOf("."));
InputStream in = file.getInputStream();
String[] split = newName.split("/");
@@ -765,7 +766,7 @@
//文件推送
InputStream inputStream = file.getInputStream();
- FtpUtil.uploadFile(FtpConfig.ftpHost, ftpPort, FtpConfig.ftpUserName, ftpPassword, ftpPath, "/", "f"+split[2], inputStream);
+ FtpUtil.uploadFile(FtpConfig.ftpHost, ftpPort, FtpConfig.ftpUserName, ftpPassword, ftpPath, "/", split[2], inputStream);
in.close();
String urls = "http://61.131.136.25:2081/zhba/" + newName;
//数据封装
@@ -862,7 +863,7 @@
"'" + attach.getTenantId() + "'" + "," +
"'" + imgurl + "'" + "," +
"'" + ip + "'" + "," +
- "'" + split[2] + "'" + "," +
+ "'" + "f"+split[2] + "'" + "," +
"'" + attach.getOriginalName() + "'" + "," +
"'" + attach.getExtension() + "'" + "," +
"'" + attach.getAttachSize() + "'" + "," +
@@ -881,7 +882,7 @@
"'" + attach.getTenantId() + "'" + "," +
"'" + imgurl + "'" + "," +
"'" + ip + "'" + "," +
- "'" + split[2] + "'" + "," +
+ "'" + "f"+ split[2] + "'" + "," +
"'" + attach.getOriginalName() + "'" + "," +
"'" + attach.getExtension() + "'" + "," +
"'" + attach.getAttachSize() + "'" + "," +
--
Gitblit v1.9.3