All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.leopard.data.dfs.service.image.Base64ImageUtil Maven / Gradle / Ivy

Go to download

分布式文件系统实现,目前只是做了基于GridFS的实现,可以在本机文件系统进行缓存。

There is a newer version: 0.9.12
Show newest version
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