chore: fix add product with video

This commit is contained in:
2026-02-22 13:26:15 +01:00
parent 9ff3a6bd9e
commit 2d9bec7392
4 changed files with 18 additions and 10 deletions
+7 -4
View File
@@ -14,6 +14,7 @@ import (
"strings"
"time"
"github.com/gabriel-vasile/mimetype"
"github.com/gin-gonic/gin"
)
@@ -140,14 +141,16 @@ func validateFileMimeType(fileHeader *multipart.FileHeader) (string, error) {
}
defer file.Close()
// Lire les premiers 512 bytes pour détecter le type MIME
buffer := make([]byte, 512)
_, err = file.Read(buffer)
mtype, err := mimetype.DetectReader(file)
if err != nil {
return "", err
}
mimeType := http.DetectContentType(buffer)
mimeType := mtype.String()
// Normaliser : couper les paramètres éventuels (ex: "video/mp4; codecs=...")
if idx := strings.Index(mimeType, ";"); idx != -1 {
mimeType = strings.TrimSpace(mimeType[:idx])
}
if !allowedMimeTypes[mimeType] {
return "", fmt.Errorf("type de fichier non autorisé: %s", mimeType)