AWS S3 Binding - Add Content-Type in the metadata request (#3216)
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>
This commit is contained in:
parent
20a46e6657
commit
8fe74b15aa
|
@ -48,7 +48,8 @@ const (
|
||||||
metadataFilePath = "filePath"
|
metadataFilePath = "filePath"
|
||||||
metadataPresignTTL = "presignTTL"
|
metadataPresignTTL = "presignTTL"
|
||||||
|
|
||||||
metadataKey = "key"
|
metatadataContentType = "Content-Type"
|
||||||
|
metadataKey = "key"
|
||||||
|
|
||||||
defaultMaxResults = 1000
|
defaultMaxResults = 1000
|
||||||
presignOperation = "presign"
|
presignOperation = "presign"
|
||||||
|
@ -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)
|
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
|
var r io.Reader
|
||||||
if metadata.FilePath != "" {
|
if metadata.FilePath != "" {
|
||||||
r, err = os.Open(metadata.FilePath)
|
r, err = os.Open(metadata.FilePath)
|
||||||
|
@ -187,9 +193,10 @@ func (s *AWSS3) create(ctx context.Context, req *bindings.InvokeRequest) (*bindi
|
||||||
}
|
}
|
||||||
|
|
||||||
resultUpload, err := s.uploader.UploadWithContext(ctx, &s3manager.UploadInput{
|
resultUpload, err := s.uploader.UploadWithContext(ctx, &s3manager.UploadInput{
|
||||||
Bucket: ptr.Of(metadata.Bucket),
|
Bucket: ptr.Of(metadata.Bucket),
|
||||||
Key: ptr.Of(key),
|
Key: ptr.Of(key),
|
||||||
Body: r,
|
Body: r,
|
||||||
|
ContentType: contentType,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("s3 binding error: uploading failed: %w", err)
|
return nil, fmt.Errorf("s3 binding error: uploading failed: %w", err)
|
||||||
|
|
Loading…
Reference in New Issue