Commit 1c790eee authored by duanjinfei's avatar duanjinfei

update check base64

parent e63c626b
...@@ -101,23 +101,19 @@ func readPrivateKey() (*ecdsa.PrivateKey, error) { ...@@ -101,23 +101,19 @@ func readPrivateKey() (*ecdsa.PrivateKey, error) {
// IsBase64ImageStr 检查字符串是否是 Base64 编码的图像数据 // IsBase64ImageStr 检查字符串是否是 Base64 编码的图像数据
func IsBase64ImageStr(imageStr string) (bool, []byte, string, string) { func IsBase64ImageStr(imageStr string) (bool, []byte, string, string) {
// 移除可能的前缀(如 "data:image/png;base64,") // 移除可能的前缀(如 "data:image/png;base64,")
imageStrArr := strings.SplitN(imageStr, ",", 2) imageStrArr := strings.Split(imageStr, ",")
base64CodePrefix := "" if len(imageStrArr) < 2 {
base64Code := "" return false, nil, "", ""
if len(imageStrArr) == 1 {
base64Code = imageStrArr[0]
base64CodePrefix = "data:image/png;base64"
} else {
base64CodePrefix = imageStrArr[0]
base64Code = imageStrArr[1]
} }
base64CodePrefix := imageStrArr[0]
base64Code := imageStrArr[1]
decodeBytes, err := base64.StdEncoding.DecodeString(base64Code) decodeBytes, err := base64.StdEncoding.DecodeString(base64Code)
if err != nil { if err != nil {
log.WithError(err).Error("base64 decode string failed") log.WithError(err).Error("base64 decode string failed")
return false, nil, "", "" return false, nil, "", ""
} }
dataSuffix := strings.Split(base64CodePrefix, ";") dataSuffix := strings.Split(base64CodePrefix, ";")
if len(dataSuffix) < 1 { if len(dataSuffix) < 2 {
return false, nil, "", "" return false, nil, "", ""
} }
formatStrArr := strings.Split(dataSuffix[0], ":") formatStrArr := strings.Split(dataSuffix[0], ":")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment