fusenapi/utils/file/base64.go
2023-08-07 19:41:44 +08:00

19 lines
413 B
Go

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