fix(relay): improve error handling for unsupported MIME types by sanitizing URLs

This commit is contained in:
CaIon
2025-06-17 22:40:41 +08:00
parent edd9049100
commit 0199896d9a
3 changed files with 18 additions and 7 deletions

View File

@@ -33,6 +33,10 @@ func GetFileBase64FromUrl(url string) (*dto.LocalFileData, error) {
base64Data := base64.StdEncoding.EncodeToString(fileBytes)
mimeType := resp.Header.Get("Content-Type")
if len(strings.Split(mimeType, ";")) > 1 {
// If Content-Type has parameters, take the first part
mimeType = strings.Split(mimeType, ";")[0]
}
if mimeType == "application/octet-stream" {
if common.DebugEnabled {
println("MIME type is application/octet-stream, trying to guess from URL or filename")