Skip to content

Commit

Permalink
fix multipart/form-data without filename and content type (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
larryhu authored and jeevatkm committed Jun 18, 2019
1 parent 84e2832 commit 0fc0257
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,19 @@ func escapeQuotes(s string) string {

func createMultipartHeader(param, fileName, contentType string) textproto.MIMEHeader {
hdr := make(textproto.MIMEHeader)
hdr.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`,
escapeQuotes(param), escapeQuotes(fileName)))
hdr.Set("Content-Type", contentType)

var contentDispositionValue string
if IsStringEmpty(fileName) {
contentDispositionValue = fmt.Sprintf(`form-data; name="%s"`, param)
} else {
contentDispositionValue = fmt.Sprintf(`form-data; name="%s"; filename="%s"`,
param, escapeQuotes(fileName))
}
hdr.Set("Content-Disposition", contentDispositionValue)

if !IsStringEmpty(contentType) {
hdr.Set(hdrContentTypeKey, contentType)
}
return hdr
}

Expand Down

0 comments on commit 0fc0257

Please sign in to comment.