@@ -77,7 +77,7 @@ func UploadURL(url string) (string, error) {
7777 return "" , err
7878 }
7979
80- return Upload (bodyBytes )
80+ return Upload (bodyBytes , "" )
8181}
8282
8383// UploadFile - same functionality as UploadURL but take in a multipart.FileHeader
@@ -90,16 +90,20 @@ func UploadFile(fileHeader *multipart.FileHeader) (string, error) {
9090 if err != nil {
9191 return "" , err
9292 }
93- return Upload (bodyBytes )
93+ return Upload (bodyBytes , fileHeader . Header . Get ( "Content-Type" ) )
9494}
9595
9696// Upload
9797// Uploads a file to S3 naming it after a hash of the file contents.
9898// Accepts a public URL
9999// returns the URL of the uploaded file and an error if there was one.
100- func Upload (bodyBytes []byte ) (string , error ) {
100+ func Upload (bodyBytes []byte , contentType string ) (string , error ) {
101101
102- extension , contentType , err := getExtension (bodyBytes )
102+ if contentType == "" {
103+ contentType = http .DetectContentType (bodyBytes )
104+ }
105+
106+ extension , err := getExtension (contentType )
103107 if err != nil {
104108 return "" , err
105109 }
@@ -120,10 +124,9 @@ func Upload(bodyBytes []byte) (string, error) {
120124}
121125
122126// Figure out file extension and content type
123- func getExtension (bytes [] byte ) (string , string , error ) {
127+ func getExtension (contentType string ) (string , error ) {
124128
125129 var extension string
126- contentType := http .DetectContentType (bytes )
127130
128131 switch contentType {
129132 case "image/jpg" :
@@ -149,10 +152,10 @@ func getExtension(bytes []byte) (string, string, error) {
149152 case "application/csv" :
150153 extension = "csv"
151154 default :
152- return "" , "" , errors .New ("unable to detect Content Type: " + contentType )
155+ return "" , errors .New ("unable to detect Content Type: " + contentType )
153156 }
154157
155- return extension , contentType , nil
158+ return extension , nil
156159}
157160
158161func VerifyEmail (to string ) (* ses.VerifyEmailIdentityOutput , error ) {
0 commit comments