You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
863 B
34 lines
863 B
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package file
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/youruser/base/internal/logic/file"
|
|
"github.com/youruser/base/internal/svc"
|
|
"github.com/zeromicro/go-zero/rest/httpx"
|
|
)
|
|
|
|
// 上传文件
|
|
func UploadFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
// Limit request body size based on config
|
|
r.Body = http.MaxBytesReader(w, r.Body, svcCtx.Config.Storage.MaxSize)
|
|
|
|
// Parse multipart form with max size
|
|
if err := r.ParseMultipartForm(svcCtx.Config.Storage.MaxSize); err != nil {
|
|
httpx.ErrorCtx(r.Context(), w, err)
|
|
return
|
|
}
|
|
|
|
l := file.NewUploadFileLogic(r.Context(), svcCtx)
|
|
resp, err := l.UploadFile(r)
|
|
if err != nil {
|
|
httpx.ErrorCtx(r.Context(), w, err)
|
|
} else {
|
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
}
|
|
}
|
|
}
|
|
|