富文本怎么存mysql 富文本存储到数据库用什么数据类型( 二 )


}
@Override
public String getName() {
return System.currentTimeMillis() + Math.random() + "." + header.split("/")[1];
}
@Override
public String getOriginalFilename() {
return System.currentTimeMillis() + (int) Math.random() * 10000 + "." + header.split("/")[1];
}
@Override
public String getContentType() {
return header.split(":")[1];
}
@Override
public boolean isEmpty() {
return imgContent == null || imgContent.length == 0;
}
@Override
public long getSize() {
return imgContent.length;
}
@Override
public byte[] getBytes() throws IOException {
return imgContent;
}
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(imgContent);
}
@Override
public void transferTo(File dest) throws IOException, IllegalStateException {
new FileOutputStream(dest).write(imgContent);
}
public static MultipartFile base64ToMultipart(String base64) {
try {
String[] baseStrs = base64.split(",");
BASE64Decoder decoder = new BASE64Decoder();
byte[] b = new byte[0];
b = decoder.decodeBuffer(baseStrs[1]);
for (int i = 0; ib.length; ++i) {
if (b[i]0) {
b[i] += 256;
}
}
return new BASE64DecodedMultipartFile(b, baseStrs[0]);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
内容接收并完成处理工具类
public class RichTextUtil {
/**
*
* @param text 富文本内容
* @return返回处理图片后的数据
*/
publicString richText(String text,MinioUtils minioUtils,MinioConfig minioConfig){
String s=new String(text);
String result=null;//返回结果
ListString imgStr = ImgBaseUtil.getImgStr(s); //每组base64编码图片
if (imgStr.isEmpty()){
return text;
}
for (String s1:imgStr){ //每个base64转换并上传
String s2= UUID.randomUUID().toString().replaceAll("-","")+".jpg"; //新的文件链接
//上传
MultipartFile multipartFile = BASE64DecodedMultipartFile.base64ToMultipart(s1);
assert multipartFile != null;
minioUtils.putObject1(multipartFile,minioConfig.getBucketName(),s2);
String foreverUrl=minioConfig.getEndpoint()+":"+minioConfig.getPort()+"/"+minioConfig.getBucketName()+"/"+s2;//永久链接
if (Objects.isNull(result)){

推荐阅读