Skip to content

Commit

Permalink
Add ContentType to Upload
Browse files Browse the repository at this point in the history
  • Loading branch information
yudppp committed Feb 28, 2020
1 parent b788cce commit ca8e60d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
21 changes: 12 additions & 9 deletions graphql/handler/transport/http_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ func (f MultipartForm) Do(w http.ResponseWriter, r *http.Request, exec graphql.G

if len(paths) == 1 {
upload = graphql.Upload{
File: file,
Size: header.Size,
Filename: header.Filename,
File: file,
Size: header.Size,
Filename: header.Filename,
ContentType: header.Header.Get("Content-Type"),
}

if err := params.AddUpload(upload, key, paths[0]); err != nil {
Expand All @@ -127,9 +128,10 @@ func (f MultipartForm) Do(w http.ResponseWriter, r *http.Request, exec graphql.G
}
for _, path := range paths {
upload = graphql.Upload{
File: &bytesReader{s: &fileBytes, i: 0, prevRune: -1},
Size: header.Size,
Filename: header.Filename,
File: &bytesReader{s: &fileBytes, i: 0, prevRune: -1},
Size: header.Size,
Filename: header.Filename,
ContentType: header.Header.Get("Content-Type"),
}

if err := params.AddUpload(upload, key, path); err != nil {
Expand Down Expand Up @@ -173,9 +175,10 @@ func (f MultipartForm) Do(w http.ResponseWriter, r *http.Request, exec graphql.G
}
defer pathTmpFile.Close()
upload = graphql.Upload{
File: pathTmpFile,
Size: header.Size,
Filename: header.Filename,
File: pathTmpFile,
Size: header.Size,
Filename: header.Filename,
ContentType: header.Header.Get("Content-Type"),
}

if err := params.AddUpload(upload, key, path); err != nil {
Expand Down
7 changes: 4 additions & 3 deletions graphql/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
)

type Upload struct {
File io.Reader
Filename string
Size int64
File io.Reader
Filename string
Size int64
ContentType string
}

func MarshalUpload(f Upload) Marshaler {
Expand Down

0 comments on commit ca8e60d

Please sign in to comment.