Skip to content

Commit a1f342e

Browse files
committed
explicit file type mappings to override system specific types
1 parent f2c0517 commit a1f342e

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

internal/firebase/cloud.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,25 +180,34 @@ func (s *CloudStorage) validateUpload(path string, data []byte) error {
180180
func (s *CloudStorage) detectContentType(path string) string {
181181
ext := strings.ToLower(filepath.Ext(path))
182182

183-
if mimeType := mime.TypeByExtension(ext); mimeType != "" {
184-
log.Printf("detected MIME type: %s for file: %s", mimeType, path)
185-
return mimeType
186-
}
187-
183+
// Prioritize explicit mappings over mime.TypeByExtension to avoid platform-specific issues
184+
// (e.g., Windows associates .csv with Excel)
188185
switch ext {
189186
case ".csv":
187+
log.Printf("detected MIME type: text/csv for file: %s", path)
190188
return "text/csv"
191189
case ".json":
190+
log.Printf("detected MIME type: application/json for file: %s", path)
192191
return "application/json"
193192
case ".txt":
193+
log.Printf("detected MIME type: text/plain for file: %s", path)
194194
return "text/plain"
195195
case ".pdf":
196+
log.Printf("detected MIME type: application/pdf for file: %s", path)
196197
return "application/pdf"
197198
case ".xlsx", ".xls":
199+
log.Printf("detected MIME type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet for file: %s", path)
198200
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
199-
default:
200-
return "application/octet-stream"
201201
}
202+
203+
// Fallback to mime.TypeByExtension for other file types
204+
if mimeType := mime.TypeByExtension(ext); mimeType != "" {
205+
log.Printf("detected MIME type: %s for file: %s", mimeType, path)
206+
return mimeType
207+
}
208+
209+
log.Printf("detected MIME type: application/octet-stream (default) for file: %s", path)
210+
return "application/octet-stream"
202211
}
203212

204213
// downloadWorker processes download jobs concurrently

0 commit comments

Comments
 (0)