From 1c4dbb1e46a25bb8e1b824cd5d580ce616316b28 Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: Thu, 04 Dec 2025 13:15:50 +0800
Subject: [PATCH] 优化表单构建关闭页签销毁复制插件
---
ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/FastDfsSysFileServiceImpl.java | 44 +++++++++++++++++++++++++++++++++++++-------
1 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/FastDfsSysFileServiceImpl.java b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/FastDfsSysFileServiceImpl.java
index 631048c..456c697 100644
--- a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/FastDfsSysFileServiceImpl.java
+++ b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/FastDfsSysFileServiceImpl.java
@@ -1,14 +1,14 @@
package com.ruoyi.file.service;
+import java.io.InputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
+import com.alibaba.nacos.common.utils.IoUtils;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.ruoyi.common.core.utils.file.FileTypeUtils;
-
-import java.io.InputStream;
/**
* FastDFS 文件存储
@@ -37,10 +37,40 @@
@Override
public String uploadFile(MultipartFile file) throws Exception
{
- InputStream inputStream = file.getInputStream();
- StorePath storePath = storageClient.uploadFile(inputStream, file.getSize(),
- FileTypeUtils.getExtension(file), null);
- inputStream.close();
- return domain + "/" + storePath.getFullPath();
+ InputStream inputStream = null;
+ try
+ {
+ inputStream = file.getInputStream();
+ StorePath storePath = storageClient.uploadFile(inputStream, file.getSize(), FileTypeUtils.getExtension(file), null);
+ return domain + "/" + storePath.getFullPath();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("FastDfs Failed to upload file", e);
+ }
+ finally
+ {
+ IoUtils.closeQuietly(inputStream);
+ }
+ }
+
+ /**
+ * FastDFS文件删除接口
+ *
+ * @param fileUrl 文件访问URL
+ * @throws Exception
+ */
+ @Override
+ public void deleteFile(String fileUrl) throws Exception
+ {
+ try
+ {
+ StorePath storePath = StorePath.parseFromUrl(fileUrl);
+ storageClient.deleteFile(storePath.getGroup(), storePath.getPath());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("FastDfs Failed to delete file: ", e);
+ }
}
}
--
Gitblit v1.9.3