|
@@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import sun.misc.BASE64Decoder;
|
|
|
+import org.springframework.mock.web.MockMultipartFile;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
@@ -123,6 +124,23 @@ public class SysFileController
|
|
|
|
|
|
@PostMapping("gljtUpload")
|
|
|
public R<SysFile> gljtUpload(MultipartFile file) {
|
|
|
+ // 检查并处理文件名长度
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ if (originalFilename != null && originalFilename.length() > 30) {
|
|
|
+ try {
|
|
|
+ String extension = "";
|
|
|
+ int dotIndex = originalFilename.lastIndexOf(".");
|
|
|
+ if (dotIndex > 0) {
|
|
|
+ extension = originalFilename.substring(dotIndex);
|
|
|
+ originalFilename = originalFilename.substring(0, dotIndex);
|
|
|
+ }
|
|
|
+ originalFilename = originalFilename.substring(0, Math.min(originalFilename.length(), 30 - extension.length())) + extension;
|
|
|
+ // 创建新的 MultipartFile 对象,使用截断后的文件名
|
|
|
+ file = new MockMultipartFile(file.getName(), originalFilename, file.getContentType(), file.getInputStream());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("文件名长度超过30个字符,请修改文件名");
|
|
|
+ }
|
|
|
+ }
|
|
|
MultipartFile shift;
|
|
|
try {
|
|
|
shift = ShiftCryptoUtils.encryptMultipartFile(file);
|