func()

in cdn-s3/s3_client.go [52:87]


func (s *Client) PutObject(key, ext string, file io.ReadSeeker) (err error) {
	newSession, err := session.NewSession(s.s3Config)
	if err != nil {
		return fmt.Errorf("failed to create session, %s", err.Error())
	}

	extType := strings.TrimPrefix(ext, ".")
	contentType := ""
	switch extType {
	case "jpg", "jpeg", "png":
		contentType = "image/" + extType
	case "svg":
		contentType = "image/svg+xml"
	case "js":
		contentType = "application/javascript"
	case "css":
		contentType = "text/css"
	case "map":
		contentType = "application/json"
	case "woff":
		contentType = "application/font-woff"
	case "woff2":
		contentType = "application/font-woff2"
	}

	_, err = s3.New(newSession).PutObject(&s3.PutObjectInput{
		Body:        file,
		Bucket:      aws.String(s.bucket),
		Key:         aws.String(key),
		ContentType: aws.String(contentType),
	})
	if err != nil {
		return fmt.Errorf("failed to put object, %s", err.Error())
	}
	return err
}