From 09dccf00d1d0e6c705535fcea691b5c437fbc874 Mon Sep 17 00:00:00 2001 From: viralauraframes Date: Tue, 21 Apr 2026 12:11:41 -0400 Subject: [PATCH 1/2] fix content type for heic image renders --- pushd_plugin.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pushd_plugin.go b/pushd_plugin.go index 8ccc766a64..377d5c52f3 100644 --- a/pushd_plugin.go +++ b/pushd_plugin.go @@ -117,9 +117,21 @@ func createMD5Hash(data []byte) string { return base64.StdEncoding.EncodeToString(hash.Sum(nil)) } +func contentTypeFromData(data []byte) string { + if len(data) >= 3 && data[0] == 0xFF && data[1] == 0xD8 && data[2] == 0xFF { + return "image/jpeg" + } + if len(data) >= 12 && string(data[4:8]) == "ftyp" { + // this would also include avif but imgproxy is set to only render heic or jpeg so this is ok. + return "image/heic" + } + return "image/jpeg" +} + func uploadToS3(data []byte, s3Key string, uploaded chan bool) { md5Hash := createMD5Hash(data) - log.Infof("Uploading rendered image to: %s with md5 hash: %s", s3Key, md5Hash) + contentType := contentTypeFromData(data) + log.Infof("Uploading rendered image to: %s with md5 hash: %s content-type: %s", s3Key, md5Hash, contentType) awsSession, err := session.NewSession() if err != nil { log.Error(err.Error()) @@ -130,7 +142,7 @@ func uploadToS3(data []byte, s3Key string, uploaded chan bool) { Body: aws.ReadSeekCloser(bytes.NewReader(data)), Bucket: aws.String(s3RenderBucket), Key: aws.String(s3Key), - ContentType: aws.String("image/jpeg"), + ContentType: aws.String(contentType), ContentMD5: aws.String(md5Hash), } From 5e02199f07eb4264490a7dd849267909bc81bafa Mon Sep 17 00:00:00 2001 From: viralauraframes Date: Tue, 21 Apr 2026 14:02:56 -0400 Subject: [PATCH 2/2] use mime from image data and pass that in to upload to s3 instead of trying to figure out type from header bytes --- processing_handler.go | 2 +- pushd_plugin.go | 18 +++--------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/processing_handler.go b/processing_handler.go index 2016642832..c81b30579b 100644 --- a/processing_handler.go +++ b/processing_handler.go @@ -438,7 +438,7 @@ func handleProcessing(reqID string, rw http.ResponseWriter, r *http.Request) { // copy imgData for thread safety imgDataForS3 := make([]byte, len(resultData.Data)) copy(imgDataForS3, resultData.Data) - uploaded = beforeResponse(imgDataForS3, cachePath) + uploaded = beforeResponse(imgDataForS3, cachePath, resultData.Type.Mime()) } defer resultData.Close() diff --git a/pushd_plugin.go b/pushd_plugin.go index 377d5c52f3..4aa72d0bb4 100644 --- a/pushd_plugin.go +++ b/pushd_plugin.go @@ -117,20 +117,8 @@ func createMD5Hash(data []byte) string { return base64.StdEncoding.EncodeToString(hash.Sum(nil)) } -func contentTypeFromData(data []byte) string { - if len(data) >= 3 && data[0] == 0xFF && data[1] == 0xD8 && data[2] == 0xFF { - return "image/jpeg" - } - if len(data) >= 12 && string(data[4:8]) == "ftyp" { - // this would also include avif but imgproxy is set to only render heic or jpeg so this is ok. - return "image/heic" - } - return "image/jpeg" -} - -func uploadToS3(data []byte, s3Key string, uploaded chan bool) { +func uploadToS3(data []byte, s3Key string, contentType string, uploaded chan bool) { md5Hash := createMD5Hash(data) - contentType := contentTypeFromData(data) log.Infof("Uploading rendered image to: %s with md5 hash: %s content-type: %s", s3Key, md5Hash, contentType) awsSession, err := session.NewSession() if err != nil { @@ -159,9 +147,9 @@ func uploadToS3(data []byte, s3Key string, uploaded chan bool) { uploaded <- true } -func beforeResponse(imageData []byte, cachePath string) chan bool { +func beforeResponse(imageData []byte, cachePath string, contentType string) chan bool { uploaded := make(chan bool) - go uploadToS3(imageData, cachePath, uploaded) + go uploadToS3(imageData, cachePath, contentType, uploaded) return uploaded }