文本预览转义处理

This commit is contained in:
kl
2021-03-18 20:12:50 +08:00
parent 2a61449ce1
commit 5cad4aa93e
2 changed files with 4 additions and 1 deletions

View File

@@ -9,9 +9,11 @@ import jodd.io.FileUtil;
import org.apache.commons.codec.binary.Base64;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.util.HtmlUtils;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
/**
* Created by kl on 2018/1/17.
@@ -37,6 +39,7 @@ public class SimTextFilePreviewImpl implements FilePreview {
File originFile = new File(response.getContent());
String charset = KkFileUtils.getFileEncode(originFile);
String fileData = FileUtil.readString(originFile, charset);
fileData = HtmlUtils.htmlEscape(fileData, StandardCharsets.UTF_8.name());
model.addAttribute("textData", Base64.encodeBase64String(fileData.getBytes()));
} catch (IOException e) {
return otherFilePreview.notSupportedFile(model, fileAttribute, e.getLocalizedMessage());