Skip to content

Commit 0fc0257

Browse files
larryhujeevatkm
authored andcommitted
fix multipart/form-data without filename and content type (#236)
1 parent 84e2832 commit 0fc0257

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

util.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,19 @@ func escapeQuotes(s string) string {
161161

162162
func createMultipartHeader(param, fileName, contentType string) textproto.MIMEHeader {
163163
hdr := make(textproto.MIMEHeader)
164-
hdr.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`,
165-
escapeQuotes(param), escapeQuotes(fileName)))
166-
hdr.Set("Content-Type", contentType)
164+
165+
var contentDispositionValue string
166+
if IsStringEmpty(fileName) {
167+
contentDispositionValue = fmt.Sprintf(`form-data; name="%s"`, param)
168+
} else {
169+
contentDispositionValue = fmt.Sprintf(`form-data; name="%s"; filename="%s"`,
170+
param, escapeQuotes(fileName))
171+
}
172+
hdr.Set("Content-Disposition", contentDispositionValue)
173+
174+
if !IsStringEmpty(contentType) {
175+
hdr.Set(hdrContentTypeKey, contentType)
176+
}
167177
return hdr
168178
}
169179

0 commit comments

Comments
 (0)