21 lines
321 B
Go
21 lines
321 B
Go
package utils
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
func Image2Base64(path string) string {
|
|
file, err := os.Open(path)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
defer file.Close()
|
|
|
|
if data, err := io.ReadAll(file); err == nil {
|
|
return "data:image/jpeg;base64," + base64.StdEncoding.EncodeToString(data)
|
|
}
|
|
return ""
|
|
|
|
}
|