upload

package
v0.0.0-...-df13ac1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxUploadSize 默认最大上传资源大小是10M
	MaxUploadSize = 10 << 20 // 使用位运算更清晰
)

Variables

View Source
var (
	// GroupMimeTypes 类型分组
	GroupMimeTypes = map[int][]string{
		1: {"image/jpeg", "image/png", "image/gif", "image/bmp", "image/svg", "image/jpg"},
		2: {"video/mp4", "video/vnd.rn-realmedia-vbr", "video/x-msvideo"},
		3: {
			"application/pdf",
			"application/msword",
			"application/vnd.ms-excel",
			"application/vnd.ms-powerpoint",
			"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
			"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
			"application/vnd.openxmlformats-officedocument.presentationml.presentation",
		},
	}

	// AllowTypes 默认允许上传的文件类型
	AllowTypes = map[string]string{
		"jpg":  "image/jpg",
		"jpeg": "image/jpeg",
		"png":  "image/png",
		"svg":  "image/svg",
		"gif":  "image/gif",
		"bmp":  "image/bmp",
		"webp": "image/webp",
		"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",
		"pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
	}
)

Functions

func ParseXOssProcess

func ParseXOssProcess(xOssProcess string) map[string]string

ParseXOssProcess 解析x-oss-process参数 示例: image/resize,m_lfit,h_200,w_200

func ProcessImageWithXOssProcess

func ProcessImageWithXOssProcess(filePath, xOssProcess string) ([]byte, error)

ProcessImageWithXOssProcess 根据x-oss-process参数处理图片 aliyun oss doc: https://help.aliyun.com/document_detail/44688.html

Types

type File

type File struct {
	FileName *multipart.FileHeader `form:"file"`
}

type FileHeader

type FileHeader struct {
	AttachmentId uint64 `json:"attachment_id"`
	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

type Upload struct {
	// contains filtered or unexported fields
}

func New

func New(cfg *config.Config, maxSize int, allowTypes []string) *Upload

New 创建一个新的上传实例

func (*Upload) GetFileInfo

func (u *Upload) GetFileInfo(filePath, xOssProcess string) (*multipart.FileHeader, []byte, error)

GetFileInfo 根据不同的上传类型获取文信息

func (*Upload) Upload

func (u *Upload) Upload(file *multipart.FileHeader, path string) (*FileHeader, error)

Upload 根据配置的上传类型选择上传方式

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL