1 Star 0 Fork 0

linngc / central-mirror

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
multipart_file.go 935 Bytes
一键复制 编辑 原始数据 按行查看 历史
linngc 提交于 2024-03-25 17:21 . add:添加附件上传检查工具方法
// Package multiparts
// @Link https://gitee.com/linngc/central-mirror
// @Copyright Copyright (c) 2024 central-mirror CLI
// @Author linngc
// @License
package multiparts
import (
"context"
"fmt"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/h2non/filetype"
)
// GetMultipartByte 根据上传的附件,获取附件信息
func GetMultipartByte(ctx context.Context, ff *ghttp.UploadFile) (b []byte, fileName string, isImage int, size int64, err error) {
open, err := ff.FileHeader.Open()
if err != nil {
return nil, "", isImage, 0, gerror.NewCode(gcode.CodeMissingConfiguration, fmt.Sprintf("待解析的上传附件异常 err %s", err.Error()))
}
data := make([]byte, ff.Size)
open.Read(data)
//contains := gstr.Contains(contentType, "image")
if filetype.IsImage(b) {
isImage = 0
}
return data, ff.Filename, isImage, ff.Size, nil
}
Go
1
https://gitee.com/linngc/central-mirror.git
git@gitee.com:linngc/central-mirror.git
linngc
central-mirror
central-mirror
4aaf4b1e930c

搜索帮助