Enhance blob storage functionality with file extension support
- Added an `Extension` field to `BlobMetadata` to store file extensions alongside existing metadata. - Updated the `SaveBlob` method to handle file extensions, ensuring they are stored and retrieved correctly. - Modified the `GetBlob` method to read blob data from the filesystem based on the stored extension. - Enhanced the `Storage` struct to manage blob files in a specified directory, improving organization and access. - Introduced utility functions for determining file extensions from MIME types, facilitating better file handling. - Added comprehensive tests for new functionalities, ensuring robust behavior across blob operations.
This commit is contained in:
@@ -248,3 +248,35 @@ func GetFileExtensionFromPath(path string) string {
|
||||
return ext
|
||||
}
|
||||
|
||||
// GetExtensionFromMimeType returns file extension based on MIME type
|
||||
func GetExtensionFromMimeType(mimeType string) string {
|
||||
// Reverse lookup of GetMimeTypeFromExtension
|
||||
mimeToExt := map[string]string{
|
||||
"application/pdf": ".pdf",
|
||||
"image/png": ".png",
|
||||
"image/jpeg": ".jpg",
|
||||
"image/gif": ".gif",
|
||||
"image/webp": ".webp",
|
||||
"image/svg+xml": ".svg",
|
||||
"video/mp4": ".mp4",
|
||||
"video/webm": ".webm",
|
||||
"audio/mpeg": ".mp3",
|
||||
"audio/wav": ".wav",
|
||||
"audio/ogg": ".ogg",
|
||||
"text/plain": ".txt",
|
||||
"text/html": ".html",
|
||||
"text/css": ".css",
|
||||
"application/javascript": ".js",
|
||||
"application/json": ".json",
|
||||
"application/xml": ".xml",
|
||||
"application/zip": ".zip",
|
||||
"application/x-tar": ".tar",
|
||||
"application/gzip": ".gz",
|
||||
}
|
||||
|
||||
if ext, ok := mimeToExt[mimeType]; ok {
|
||||
return ext
|
||||
}
|
||||
return "" // No extension for unknown MIME types
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user