From e8b69fba0306dc0af25654d9327655463666bde4 Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Tue, 2 Jul 2024 08:52:28 +0200 Subject: [PATCH] Set correct Content-Type --- mediaapi/routing/download.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mediaapi/routing/download.go b/mediaapi/routing/download.go index f2303b3f2..15544d3c8 100644 --- a/mediaapi/routing/download.go +++ b/mediaapi/routing/download.go @@ -840,6 +840,10 @@ func (r *downloadRequest) fetchRemoteFile( } defer resp.Body.Close() // nolint: errcheck + // If this wasn't a multipart response, set the Content-Type now. Will be overwritten + // by the multipart Content-Type below. + r.MediaMetadata.ContentType = types.ContentType(resp.Header.Get("Content-Type")) + var contentLength int64 var reader io.Reader var parseErr error @@ -869,6 +873,8 @@ func (r *downloadRequest) fetchRemoteFile( if !first { readCloser := io.NopCloser(p) contentLength, reader, parseErr = r.GetContentLengthAndReader(p.Header.Get("Content-Length"), readCloser, maxFileSizeBytes) + // For multipart requests, we need to get the Content-Type of the second part, which is the actual media + r.MediaMetadata.ContentType = types.ContentType(p.Header.Get("Content-Type")) break } @@ -890,7 +896,6 @@ func (r *downloadRequest) fetchRemoteFile( } r.MediaMetadata.FileSizeBytes = types.FileSizeBytes(contentLength) - r.MediaMetadata.ContentType = types.ContentType(resp.Header.Get("Content-Type")) dispositionHeader := resp.Header.Get("Content-Disposition") if _, params, e := mime.ParseMediaType(dispositionHeader); e == nil {