package api import ( "fmt" "github.com/gin-gonic/gin" "os" "uploader/errors" "uploader/global" "uploader/utils/result" ) func DeleteFile(c *gin.Context) (result.Data, error) { objectName := c.PostForm("file") err := global.Storage.Delete(objectName) if err != nil { return nil, errors.NewBusinessError("删除错误") } return nil, nil } func UploadFile(c *gin.Context) (result.Data, error) { filePath := c.PostForm("file") destPath := c.PostForm("dest") isDeleteLocal := c.DefaultPostForm("is_delete_local", "0") _, err := os.Stat(filePath) if err != nil { return nil, errors.NewBusinessError("文件不存在") } fmt.Println(filePath, destPath, isDeleteLocal) url, err := global.Storage.Upload(filePath, destPath) if err != nil { fmt.Println(err.Error()) return nil, err } if isDeleteLocal == "1" { os.Remove(filePath) } data := result.Data{"url": url} return data, nil }