diff --git a/hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/ConfigManager.java b/hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/ConfigManager.java index bc87c2541..18ac9a352 100644 --- a/hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/ConfigManager.java +++ b/hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/ConfigManager.java @@ -4,7 +4,8 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baidu.ueditor.define.ActionMap; -import org.hsweb.commons.file.FileUtils; +import lombok.extern.slf4j.Slf4j; +import org.hswebframework.utils.file.FileUtils; import java.io.*; import java.util.*; @@ -14,6 +15,7 @@ import java.util.*; * * @author hancong03@baidu.com */ +@Slf4j public final class ConfigManager { private final String rootPath; @@ -147,9 +149,9 @@ public final class ConfigManager { private void initEnv() throws IOException { try { - JSONObject jsonConfig = JSON.parseObject(FileUtils.reader2String("config/ueditor.json")); - this.jsonConfig = jsonConfig; + this.jsonConfig = JSON.parseObject(FileUtils.reader2String("ueditor-config.json")); } catch (Exception e) { + log.warn("read ueditor config file error", e); this.jsonConfig = null; } diff --git a/hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/org/hswebframework/web/thirdpart/ueditor/UeditorController.java b/hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/org/hswebframework/web/thirdpart/ueditor/UeditorController.java index e0c360b7a..d50b0f6ca 100644 --- a/hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/org/hswebframework/web/thirdpart/ueditor/UeditorController.java +++ b/hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/org/hswebframework/web/thirdpart/ueditor/UeditorController.java @@ -7,6 +7,8 @@ import com.baidu.ueditor.define.FileType; import com.baidu.ueditor.define.State; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.commons.fileupload.ParameterParser; +import org.hswebframework.web.WebUtil; import org.hswebframework.web.service.file.FileInfoService; import org.hswebframework.web.service.file.FileService; import org.springframework.beans.factory.annotation.Value; @@ -20,6 +22,9 @@ import javax.annotation.PostConstruct; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.Map; +import java.util.Optional; /** * ueditor 服务端实现 @@ -62,8 +67,19 @@ public class UeditorController { */ @RequestMapping(method = RequestMethod.POST, consumes = "multipart/form-data") @ApiOperation("上传文件") - public String upload(@RequestParam(value = "upfile", required = false) MultipartFile file) throws IOException { + public String upload(@RequestParam(value = "upfile", required = false) MultipartFile file,HttpServletRequest request) throws IOException { String fileName = file.getOriginalFilename(); + String contentType = Optional.ofNullable(request) + .orElseThrow(UnsupportedOperationException::new) + .getContentType(); + ParameterParser parser = new ParameterParser(); + Map params = parser.parse(contentType, ';'); + if (params.get("charset") == null) { + try { + fileName = new String(file.getOriginalFilename().getBytes("ISO-8859-1"), "utf-8"); + } catch (@SuppressWarnings("all") UnsupportedEncodingException ignore) { + } + } String suffix = FileType.getSuffixByFilename(fileName); String path = fileService.saveStaticFile(file.getInputStream(), System.currentTimeMillis() + suffix);