mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2025-10-25 02:09:09 +08:00
指定Base64转码采用Apache Commons-code中的实现,修复base64部分jdk版本下出现的异常
This commit is contained in:
@@ -5,14 +5,13 @@ import cn.keking.model.ReturnResponse;
|
||||
import cn.keking.service.FilePreview;
|
||||
import cn.keking.utils.DownloadUtils;
|
||||
import cn.keking.utils.KkFileUtils;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.Base64Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* Created by kl on 2018/1/17.
|
||||
@@ -38,7 +37,7 @@ public class SimTextFilePreviewImpl implements FilePreview {
|
||||
File originFile = new File(response.getContent());
|
||||
String charset = KkFileUtils.getFileEncode(originFile);
|
||||
String fileData = FileUtils.readFileToString(originFile, charset);
|
||||
model.addAttribute("textData", Base64Utils.encodeToString(fileData.getBytes(StandardCharsets.UTF_8)));
|
||||
model.addAttribute("textData", Base64.encodeBase64String(fileData.getBytes()));
|
||||
} catch (IOException e) {
|
||||
return otherFilePreview.notSupportedFile(model, fileAttribute, e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user