file

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAndConvertFile added in v1.0.5

func CheckAndConvertFile(file io.Reader, fileName string) (io.Reader, error)

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

func CleanupOldFiles(uploadDirectory string, olderThan time.Duration) (int, error)

CleanupOldFiles deletes files older than the specified duration.

func DeleteFile

func DeleteFile(filename, uploadDirectory string) error

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

func DeleteMultipleFiles(filenames []string, uploadDirectory string) error

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

func FileExists(filename, uploadDirectory string) bool

FileExists checks if a file exists in the upload directory.

func GetFileInfo added in v1.3.7

func GetFileInfo(filename, uploadDirectory string) (os.FileInfo, error)

GetFileInfo returns information about a file in the upload directory.

func GetFileSize added in v1.3.7

func GetFileSize(filename, uploadDirectory string) (int64, error)

GetFileSize returns the size of a file in the upload directory.

func GetFileStats added in v1.3.7

func GetFileStats(uploadDirectory string) (fileCount int, totalSize int64, err error)

GetFileStats returns statistics about files in the upload directory.

func GetImageInfo added in v1.3.7

func GetImageInfo(file io.Reader) (string, image.Config, error)

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

func IsImageFormatSupported(fileName string) bool

IsImageFormatSupported checks if the file format is supported for WebP conversion.

func ListFiles added in v1.3.7

func ListFiles(uploadDirectory string) ([]string, error)

ListFiles lists all files in the upload directory.

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.

Jump to

Keyboard shortcuts

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