Skip to content

Commit 09dccf0

Browse files
fix content type for heic image renders
1 parent 054059a commit 09dccf0

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

pushd_plugin.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,21 @@ func createMD5Hash(data []byte) string {
117117
return base64.StdEncoding.EncodeToString(hash.Sum(nil))
118118
}
119119

120+
func contentTypeFromData(data []byte) string {
121+
if len(data) >= 3 && data[0] == 0xFF && data[1] == 0xD8 && data[2] == 0xFF {
122+
return "image/jpeg"
123+
}
124+
if len(data) >= 12 && string(data[4:8]) == "ftyp" {
125+
// this would also include avif but imgproxy is set to only render heic or jpeg so this is ok.
126+
return "image/heic"
127+
}
128+
return "image/jpeg"
129+
}
130+
120131
func uploadToS3(data []byte, s3Key string, uploaded chan bool) {
121132
md5Hash := createMD5Hash(data)
122-
log.Infof("Uploading rendered image to: %s with md5 hash: %s", s3Key, md5Hash)
133+
contentType := contentTypeFromData(data)
134+
log.Infof("Uploading rendered image to: %s with md5 hash: %s content-type: %s", s3Key, md5Hash, contentType)
123135
awsSession, err := session.NewSession()
124136
if err != nil {
125137
log.Error(err.Error())
@@ -130,7 +142,7 @@ func uploadToS3(data []byte, s3Key string, uploaded chan bool) {
130142
Body: aws.ReadSeekCloser(bytes.NewReader(data)),
131143
Bucket: aws.String(s3RenderBucket),
132144
Key: aws.String(s3Key),
133-
ContentType: aws.String("image/jpeg"),
145+
ContentType: aws.String(contentType),
134146
ContentMD5: aws.String(md5Hash),
135147
}
136148

0 commit comments

Comments
 (0)