
io.leopard.data.dfs.service.image.Base64ImageUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leopard-dfs Show documentation
Show all versions of leopard-dfs Show documentation
分布式文件系统实现,目前只是做了基于GridFS的实现,可以在本机文件系统进行缓存。
package io.leopard.data.dfs.service.image;
import org.springframework.util.Base64Utils;
import org.springframework.util.StringUtils;
public class Base64ImageUtil {
public static byte[] decodeFromString(String str) {
if (StringUtils.isEmpty(str)) {
return null;
}
if (!str.startsWith("data:image")) {
return null;
}
if (str.startsWith("data:image/png;base64,")) {
return Base64Utils.decodeFromString(str.substring(22));
}
else if (str.startsWith("data:image/jpeg;base64,")) {
return Base64Utils.decodeFromString(str.substring(23));
}
else {
throw new IllegalArgumentException("未知图片类型.");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy