检查上传的图片尺寸是否符合要求

This commit is contained in:
gazebo
2019-09-30 17:06:47 +08:00
parent 22693ea969
commit b11e2e5d1e
2 changed files with 47 additions and 31 deletions

View File

@@ -1,19 +1,20 @@
package model
import "strings"
const (
ImgTypeLocal = 0 // 京西自己用的,不需要上传至平台
ImgTypeMain = 1 // 商品主图
ImgTypeDesc = 2 // 商品描述详情
MimeTypeJpeg = "image/jpeg"
MimeTypePng = "image/png"
)
var (
ValidMimeTypes = map[string][]string{
"image/jpeg": []string{"jpeg", "jpg"},
"image/png": []string{"png"},
// "image/gif": []string{"gif"}, // 美团不支持GIF
"video/mpeg": []string{"mpeg", "mpg"},
"video/mp4": []string{"mp4", "m4v"},
ValidMimeTypes = map[string]int{
MimeTypeJpeg: 1,
MimeTypePng: 1,
}
)
@@ -33,3 +34,11 @@ type DataResource struct {
Remark string `orm:"size(1024)" json:"remark"`
}
func GetValidMimeTypeDesc() (desc string) {
strList := []string{}
for k := range ValidMimeTypes {
strList = append(strList, k)
}
return strings.Join(strList, ",")
}