Skip to content

Commit

Permalink
Merge pull request #1286 from bcgov/dev-rook-RQ-FOIMOD-3551
Browse files Browse the repository at this point in the history
set content type for word, pdf and excel files for crawler
  • Loading branch information
richard-aot authored Jan 28, 2025
2 parents a6933cd + fee43b8 commit 64aa964
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions computingservices/OpenInfoServices/lib/awslib/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,24 @@ func CopyS3(sourceBucket string, sourcePrefix string, filemappings []AdditionalF
var contentType string
if strings.EqualFold(filepath.Ext(bucket+"/"+sourceKey), ".html") {
contentType = "text/html"
} else if strings.EqualFold(filepath.Ext(bucket+"/"+sourceKey), ".pdf") {
contentType = "application/pdf"
} else if strings.EqualFold(filepath.Ext(bucket+"/"+sourceKey), ".docx") {
contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
} else if strings.EqualFold(filepath.Ext(bucket+"/"+sourceKey), ".xlsx") {
contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
} else {
// Set default content type or leave it unset
contentType = "application/octet-stream"
}

_, err := svc.CopyObject(context.TODO(), &s3.CopyObjectInput{
Bucket: aws.String(destBucket),
CopySource: aws.String(bucket + "/" + sourceKey),
Key: aws.String(destKey),
ACL: types.ObjectCannedACLPublicRead,
ContentType: aws.String(contentType),
Bucket: aws.String(destBucket),
CopySource: aws.String(bucket + "/" + sourceKey),
Key: aws.String(destKey),
ACL: types.ObjectCannedACLPublicRead,
ContentType: aws.String(contentType),
MetadataDirective: types.MetadataDirectiveReplace,
})
if err != nil {
log.Fatalf("unable to copy item %q, %v", sourceKey, err)
Expand Down

0 comments on commit 64aa964

Please sign in to comment.