fix: fixed bug for generating the upload file path

This commit is contained in:
RockYang
2023-10-05 18:09:42 +08:00
parent c5776ce41f
commit f971ec5d34
5 changed files with 31 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ import (
"chatplus/utils"
"fmt"
"github.com/gin-gonic/gin"
"net/url"
"os"
"path/filepath"
"strings"
@@ -42,7 +43,11 @@ func (s LocalStorage) PutFile(ctx *gin.Context, name string) (string, error) {
}
func (s LocalStorage) PutImg(imageURL string, useProxy bool) (string, error) {
filename := filepath.Base(imageURL)
parse, err := url.Parse(imageURL)
if err != nil {
return "", fmt.Errorf("error with parse image URL: %v", err)
}
filename := filepath.Base(parse.Path)
filePath, err := utils.GenUploadPath(s.config.BasePath, filename)
if err != nil {
return "", fmt.Errorf("error with generate image dir: %v", err)