Skip to content
Permalink
Browse files

Fixed mime type detection to be better using file path

  • Loading branch information...
eko committed May 21, 2019
1 parent c76f1f2 commit def5e546392acfe7303ad8cdf02ca47e1ee51ed2
Showing with 5 additions and 2 deletions.
  1. +5 −2 middleware.go
@@ -183,8 +183,6 @@ func mapTemporaryFileToOperations() error {
return fmt.Errorf("Could not read multipart file. Reason: %v", err)
}

mimeType, _ := mimetype.Detect(data)

f, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("graphqlupload-*%s", filepath.Ext(handle.Filename)))
if err != nil {
return fmt.Errorf("Unable to create temporary file. Reason: %v", err)
@@ -195,6 +193,11 @@ func mapTemporaryFileToOperations() error {
return fmt.Errorf("Could not write temporary file. Reason: %v", err)
}

mimeType, _, err := mimetype.DetectFile(f.Name())
if err != nil {
return fmt.Errorf("Could not determine file MIME type. Reason: %v", err)
}

upload := &GraphQLUpload{
MIMEType: mimeType,
Filename: handle.Filename,

0 comments on commit def5e54

Please sign in to comment.
You can’t perform that action at this time.