Documentation ¶
Index ¶
Constants ¶
View Source
const (
// MaxUploadSize 默认最大上传资源大小是10M
MaxUploadSize = 10 * 1024 * 1024
)
Variables ¶
View Source
var AllowTypes = map[string]string{
"jpg": "image/jpg",
"jpeg": "image/jpeg",
"png": "image/png",
"svg": "image/svg",
"gif": "image/gif",
"bmp": "image/bmp",
"mp3": "audio/mpeg",
"mp4": "video/mp4",
"avi": "video/x-msvideo",
"rmvb": "video/vnd.rn-realmedia-vbr",
"pdf": "application/pdf",
"xls": "application/vnd.ms-excel",
"xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"ppt": "application/vnd.ms-powerpoint",
"doc": "application/msword",
"docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
}
AllowTypes 默认允许上传的文件类型
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct {
FileName *multipart.FileHeader `form:"file"`
}
type FileHeader ¶
type FileHeader struct { Filename string `json:"file_name"` // 图片新名称 FileSize int64 `json:"file_size"` // 图片大小 FilePath string `json:"file_path"` // 相对路径地址 OriginName string `json:"origin_name"` // 图片原名称 MimeType string `json:"mime_type"` // 附件mime类型 Extension string `json:"extension"` // 附件后缀名 }
FileHeader 文件参数
type Upload ¶
func New ¶
New @Description: 携带上传参数 并且实例化 @param max @param allowTypes 允许的文件类型 如:[]string{"jpg"", "png", "gif"} @return *Upload
func (*Upload) UploadToLocal ¶
func (u *Upload) UploadToLocal(config *config.Config, file *multipart.FileHeader, path string) (*FileHeader, error)
UploadToLocal @Description: 上传图片 @receiver u @param file 请求的文件 @param path 子目录名称 @return *FileHeader @return error
func (Upload) UploadToOss ¶
func (u Upload) UploadToOss(config *config.Config, file *multipart.FileHeader, object string) (*FileHeader, error)
UploadToOss @Description: 上传资源到oss上 @receiver u @param config @param file @param object 上传到oss的目录结构 支持子目录 如:foo foo/bar foo/bar/baz @return *FileHeader @return error @author cx
Click to show internal directories.
Click to hide internal directories.