Documentation
¶
Index ¶
- func CheckAndConvertFile(file io.Reader, fileName string) (io.Reader, error)
- func CheckAndConvertFileWithOptions(file io.Reader, fileName string, lossless bool, quality float32) (io.Reader, error)
- func CleanupOldFiles(uploadDirectory string, olderThan time.Duration) (int, error)
- func DeleteFile(filename, uploadDirectory string) error
- func DeleteMultipleFiles(filenames []string, uploadDirectory string) error
- func FileExists(filename, uploadDirectory string) bool
- func GetFileInfo(filename, uploadDirectory string) (os.FileInfo, error)
- func GetFileSize(filename, uploadDirectory string) (int64, error)
- func GetFileStats(uploadDirectory string) (fileCount int, totalSize int64, err error)
- func GetImageInfo(file io.Reader) (string, image.Config, error)
- func GetSupportedImageFormats() []string
- func IsImageFormatSupported(fileName string) bool
- func ListFiles(uploadDirectory string) ([]string, error)
- func UploadFile(file io.Reader, fileName, uploadDirectory string, convertToWebP bool) (string, error)
- func UploadMultipleFiles(files []io.Reader, fileNames []string, uploadDirectory string, ...) ([]string, error)
- type UploadResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckAndConvertFile ¶ added in v1.0.5
CheckAndConvertFile checks if a file is an image and converts it to WebP. Returns the original file if the format is unsupported, or the WebP-converted file. Returns an error if conversion fails.
func CheckAndConvertFileWithOptions ¶ added in v1.3.7
func CheckAndConvertFileWithOptions(file io.Reader, fileName string, lossless bool, quality float32) (io.Reader, error)
CheckAndConvertFileWithOptions checks if a file is an image and converts it to WebP with custom options. Returns the original file if the format is unsupported, or the WebP-converted file. Returns an error if conversion fails.
func CleanupOldFiles ¶ added in v1.3.7
CleanupOldFiles deletes files older than the specified duration.
func DeleteFile ¶
DeleteFile removes a single file from the specified directory. Returns an error if the file does not exist or deletion fails.
func DeleteMultipleFiles ¶ added in v1.0.3
DeleteMultipleFiles deletes multiple files and returns an error if any deletions fail. Returns nil if all deletions succeed.
func FileExists ¶ added in v1.3.7
FileExists checks if a file exists in the upload directory.
func GetFileInfo ¶ added in v1.3.7
GetFileInfo returns information about a file in the upload directory.
func GetFileSize ¶ added in v1.3.7
GetFileSize returns the size of a file in the upload directory.
func GetFileStats ¶ added in v1.3.7
GetFileStats returns statistics about files in the upload directory.
func GetImageInfo ¶ added in v1.3.7
GetImageInfo attempts to get basic information about the image.
func GetSupportedImageFormats ¶ added in v1.3.7
func GetSupportedImageFormats() []string
GetSupportedImageFormats returns a list of supported image formats for WebP conversion.
func IsImageFormatSupported ¶ added in v1.3.7
IsImageFormatSupported checks if the file format is supported for WebP conversion.
func UploadFile ¶
func UploadFile(file io.Reader, fileName, uploadDirectory string, convertToWebP bool) (string, error)
UploadFile uploads a single file to the specified directory. Optionally converts images to WebP format and generates a unique filename. Returns the unique filename or an error if the upload fails.
func UploadMultipleFiles ¶ added in v1.0.3
func UploadMultipleFiles(files []io.Reader, fileNames []string, uploadDirectory string, convertToWebP bool) ([]string, error)
UploadMultipleFiles uploads multiple files and rolls back if any fail. Returns a list of uploaded filenames or an error if any upload fails.
Types ¶
type UploadResult ¶ added in v1.3.7
type UploadResult struct {
Filename string // Filename is the unique generated filename
OriginalName string // OriginalName is the original filename
Size int64 // Size is the file size in bytes
UploadTime time.Time // UploadTime is when the file was uploaded
FileType string // FileType is the detected file type
}
UploadResult represents the result of a file upload operation.
func UploadMultipartFile ¶ added in v1.3.7
func UploadMultipartFile(fileHeader *multipart.FileHeader, uploadDirectory string, convertToWebP bool) (*UploadResult, error)
UploadMultipartFile handles file upload from HTTP multipart form.