.mp3 upload fix
This commit is contained in:
parent
e689f34212
commit
8f719c2a32
|
|
@ -156,6 +156,28 @@ func (h *Handler) UploadMedia(c *fiber.Ctx) error {
|
|||
"audio/aac": true, "audio/webm": true, "video/ogg": true, "video/webm": true,
|
||||
"audio/x-wav": true, "audio/x-m4a": true, "audio/flac": true,
|
||||
}
|
||||
// DetectContentType can return "application/octet-stream" for some files (often via clients
|
||||
// like Postman). If that happens, fall back to extension-based detection.
|
||||
if contentType == "application/octet-stream" {
|
||||
filenameLower := strings.ToLower(fileHeader.Filename)
|
||||
lastDot := strings.LastIndex(filenameLower, ".")
|
||||
ext := ""
|
||||
if lastDot != -1 && lastDot+1 < len(filenameLower) {
|
||||
ext = filenameLower[lastDot+1:]
|
||||
}
|
||||
extMap := map[string]string{
|
||||
"mp3": "audio/mpeg",
|
||||
"wav": "audio/wav",
|
||||
"ogg": "audio/ogg",
|
||||
"m4a": "audio/mp4",
|
||||
"aac": "audio/aac",
|
||||
"webm": "audio/webm",
|
||||
"flac": "audio/flac",
|
||||
}
|
||||
if ct, ok := extMap[ext]; ok {
|
||||
contentType = ct
|
||||
}
|
||||
}
|
||||
if !allowedAudio[contentType] {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{
|
||||
Message: "Invalid file type",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user