fusenapi/utils/file/base64.go

19 lines
413 B
Go
Raw Normal View History

2023-08-07 04:02:11 +00:00
package file
import (
"encoding/base64"
2023-08-07 11:41:44 +00:00
"net/http"
2023-08-07 04:02:11 +00:00
"strings"
)
2023-08-07 11:41:44 +00:00
func FileBase64ToByte(fileData string) ([]byte, string, error) {
2023-08-07 04:02:11 +00:00
RBase64Point := strings.LastIndex(fileData, ";base64,") + 8
fileDataStr := fileData[RBase64Point:]
dist, err := base64.StdEncoding.DecodeString(fileDataStr)
if err != nil {
2023-08-07 11:41:44 +00:00
return nil, "", err
2023-08-07 04:02:11 +00:00
}
2023-08-07 11:41:44 +00:00
contentType := http.DetectContentType(dist)
return dist, contentType, nil
2023-08-07 04:02:11 +00:00
}