Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS S3 Binding - Add Content-Type in the metadata request #3216

Merged
merged 4 commits into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions bindings/aws/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const (
metadataFilePath = "filePath"
metadataPresignTTL = "presignTTL"

metadataKey = "key"
metatadataContentType = "Content-Type"
metadataKey = "key"

defaultMaxResults = 1000
presignOperation = "presign"
Expand Down Expand Up @@ -172,6 +173,11 @@ func (s *AWSS3) create(ctx context.Context, req *bindings.InvokeRequest) (*bindi
s.logger.Debugf("s3 binding error: key not found. generating key %s", key)
}

var contentType *string
contentTypeStr := strings.TrimSpace(req.Metadata[metatadataContentType])
if contentTypeStr != "" {
contentType = &contentTypeStr
}
var r io.Reader
if metadata.FilePath != "" {
r, err = os.Open(metadata.FilePath)
Expand All @@ -187,9 +193,10 @@ func (s *AWSS3) create(ctx context.Context, req *bindings.InvokeRequest) (*bindi
}

resultUpload, err := s.uploader.UploadWithContext(ctx, &s3manager.UploadInput{
Bucket: ptr.Of(metadata.Bucket),
Key: ptr.Of(key),
Body: r,
Bucket: ptr.Of(metadata.Bucket),
Key: ptr.Of(key),
Body: r,
ContentType: contentType,
})
if err != nil {
return nil, fmt.Errorf("s3 binding error: uploading failed: %w", err)
Expand Down