js
var index = layui.layedit.build('noticeInformationContent', {
area: ['500px', '400px'],
url: 'NI/uploadconimage' //接口url
content: function (val) {
layui.layedit.sync(index);
var content = layui.layedit.getContent(index);
if (content.length > 1600) {
java
@PostMapping("/NI/uploadconimage")
public Map<String, Object> uploadconimage(MultipartFile file) {
Map<String, Object> result = new HashMap<>();
try (BufferedInputStream in = new BufferedInputStream(file.getInputStream());
ByteArrayOutputStream out = new ByteArrayOutputStream()) {
byte[] bytes = new byte[2 * 1024];
while ((len = in.read(bytes)) > 0) {
out.write(bytes, 0, len);
byte[] byteArray = out.toByteArray();
BASE64Encoder encoder = new BASE64Encoder();
String encode = encoder.encode(byteArray);
Map<String, Object> data = new HashMap<>();
data.put("src", "data:image/jpg;base64," + encode);
// data.put("src", "templetdata/static/images/banner.jpg");
data.put("title", file.getOriginalFilename());
result.put("code", 0);//重点:layui富文本不是code==200
result.put("msg", "上传成功");
result.put("data", data);
log.error(e.getMessage(), e);
result.put("msg", "上传失败!");