Documentation
¶
Index ¶
- func Canon(k string) string
- func ContentTypeByExt(extOrName string) string
- func DetectContentType(fh *multipart.FileHeader) (string, error)
- func DetectContentTypeFromFile(fileName string, first512 []byte) string
- func DetectContentTypeFromHeader(fileHeader *multipart.FileHeader) (string, error)
- func DetectMIMEType(fileHeader *multipart.FileHeader) (string, error)
- func Disposition(fileName string, inline bool) string
- func Extension(fh *multipart.FileHeader) string
- func OpenAndDetect(fh *multipart.FileHeader) (io.ReadCloser, string, error)
- func ReadAll(fh *multipart.FileHeader) ([]byte, error)
- func ReadChunked(fh *multipart.FileHeader, bufSize int, fn func([]byte) error) error
- func SanitizeFilename(name string) string
- func SaveTo(fh *multipart.FileHeader, dstPath string, perm os.FileMode) error
- func SaveToDir(fh *multipart.FileHeader, dir string, perm os.FileMode) (string, error)
- func ValidateContentType(fh *multipart.FileHeader, allowed []string) (string, error)
- func ValidateMaxSize(fh *multipart.FileHeader, maxBytes int64) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContentTypeByExt ¶
ContentTypeByExt returns a content-type for a filename extension like ".png" or "png". It uses mime.TypeByExtension and falls back to a few common types. Empty string if unknown.
func DetectContentType ¶
func DetectContentType(fh *multipart.FileHeader) (string, error)
DetectContentType returns the MIME type by sniffing up to the first 512 bytes.
func DetectContentTypeFromFile ¶
DetectContentTypeFromFile tries to determine a content-type from a file name, optionally sniffing up to the first 512 bytes if provided. If no good guess is available, returns application/octet-stream.
func DetectContentTypeFromHeader ¶
func DetectContentTypeFromHeader(fileHeader *multipart.FileHeader) (string, error)
func DetectMIMEType ¶
func DetectMIMEType(fileHeader *multipart.FileHeader) (string, error)
func Disposition ¶
Disposition builds a Content-Disposition header value. If inline==true => "inline; filename*=utf-8”<url-escaped>"; else "attachment; ...".
func Extension ¶
func Extension(fh *multipart.FileHeader) string
Extension returns the file extension (lowercase, no dot).
func OpenAndDetect ¶
func OpenAndDetect(fh *multipart.FileHeader) (io.ReadCloser, string, error)
OpenAndDetect opens the file and also returns its content type (first 512 bytes read). The returned io.ReadCloser starts *after* the bytes used for detection.
func ReadAll ¶
func ReadAll(fh *multipart.FileHeader) ([]byte, error)
ReadAll reads the entire file content into memory. Use with caution for large uploads.
func ReadChunked ¶
ReadChunked calls fn for each chunk read from the file. Useful for processing large files without loading into memory.
func SanitizeFilename ¶
SanitizeFilename removes potentially dangerous path separators and control chars.
func SaveTo ¶
SaveTo saves the file to the given destination path. It creates parent directories if needed.
func ValidateContentType ¶
func ValidateContentType(fh *multipart.FileHeader, allowed []string) (string, error)
ValidateContentType ensures the file's content type is one of the allowed list.
func ValidateMaxSize ¶
func ValidateMaxSize(fh *multipart.FileHeader, maxBytes int64) error
ValidateMaxSize checks if the file size is within maxBytes.
Types ¶
This section is empty.