You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
914 B
Go
43 lines
914 B
Go
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
|
|
}
|