Skip to content

Commit 6ed6fc2

Browse files
committed
Refactor addFilePart to use base64 encoding for file content
1 parent 083dfa7 commit 6ed6fc2

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

httpclient/multipartrequest.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,12 @@ func addFilePart(writer *multipart.Writer, fieldName, filePath string, contentTy
145145
contentType = ct
146146
}
147147

148-
var part io.Writer
149-
if h, ok := headersMap[fieldName]; ok {
150-
part, err = writer.CreatePart(CustomFormDataHeader(fieldName, filepath.Base(filePath), contentType, h))
151-
} else {
152-
part, err = writer.CreateFormFile(fieldName, filepath.Base(filePath))
153-
}
148+
header := textproto.MIMEHeader{}
149+
header.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`, fieldName, filepath.Base(filePath)))
150+
header.Set("Content-Type", contentType)
151+
header.Set("Content-Transfer-Encoding", "base64")
154152

153+
part, err := writer.CreatePart(header)
155154
if err != nil {
156155
log.Error("Failed to create form file part", zap.String("fieldName", fieldName), zap.Error(err))
157156
return err

0 commit comments

Comments
 (0)