Skip to content

Commit

Permalink
AWS S3 Binding - Add Content-Type in the metadata request (dapr#3216)
Browse files Browse the repository at this point in the history
Signed-off-by: luigirende <luigirende@gmail.com>
Signed-off-by: luiren <luigirende@gmail.com>
Signed-off-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com>
Co-authored-by: luiren <luigi.rende@assistdigital.com>
Co-authored-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com>
  • Loading branch information
3 people authored and berndverst committed Nov 9, 2023
1 parent b2a0393 commit e2cdb65
Showing 1 changed file with 11 additions and 4 deletions.
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

0 comments on commit e2cdb65

Please sign in to comment.