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

Try to detect Content Type for s3 objects #19

Merged
merged 1 commit into from
Aug 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions s3/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"io/ioutil"
"strings"

"net/http"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/graymeta/stow"
Expand Down Expand Up @@ -113,10 +115,15 @@ func (c *container) Put(name string, r io.Reader, size int64, metadata map[strin
return nil, errors.Wrap(err, "unable to create or update item, preparing metadata")
}

// Get Content Type as string
// https://golang.org/pkg/net/http/#DetectContentType
contentType := http.DetectContentType(content)

params := &s3.PutObjectInput{
Bucket: aws.String(c.name), // Required
Key: aws.String(name), // Required
ContentLength: aws.Int64(size),
ContentType: &contentType,
Body: bytes.NewReader(content),
Metadata: mdPrepped, // map[string]*string
}
Expand Down