Initial commit

This commit is contained in:
Donny
2019-04-22 20:46:32 +08:00
commit 49ab8aadd1
25441 changed files with 4055000 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
package http
import (
"io/ioutil"
"net/http"
"time"
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
)
const maxSize = 1024 * 1024 * 20
func upbfs(c *bm.Context) {
var req = c.Request
// read the file
req.ParseMultipartForm(maxSize)
log.Info("Request Info: %v, %v, %v", req.PostForm, req.Form, req.MultipartForm)
file, _, err := req.FormFile("file")
if err != nil {
renderErrMsg(c, ecode.RequestErr.Code(), "文件为空")
return
}
defer file.Close()
content, err := ioutil.ReadAll(file)
if err != nil {
log.Error("resource uploadFile.ReadAll error(%v)", err)
return
}
// parse file, get type, size
ftype := http.DetectContentType(content)
if ftype != "image/jpeg" && ftype != "image/png" && ftype != "image/webp" && ftype != "image/gif" {
log.Error("filetype not allow file type(%s)", ftype)
renderErrMsg(c, ecode.RequestErr.Code(), "检查文件类型,需为图片")
return
}
fsize := len(content)
if fsize > maxSize {
renderErrMsg(c, ecode.RequestErr.Code(), "文件过大不支持超过20M的文件")
return
}
// upload file to BFS
c.JSON(tvSrv.Upload(c, "", ftype, time.Now().Unix(), content))
}