Skip to content

Commit fe5d557

Browse files
authored
Merge pull request #273 from deploymenttheory/fix-multipart_uploads
updated function comments and updated documentation
2 parents 4b83bc9 + 424a9a0 commit fe5d557

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Diff for: httpclient/multipartrequest.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type UploadState struct {
6767
func (c *Client) DoMultiPartRequest(method, endpoint string, files map[string][]string, formDataFields map[string]string, fileContentTypes map[string]string, formDataPartHeaders map[string]http.Header, encodingType string, out interface{}) (*http.Response, error) {
6868
if encodingType != "byte" && encodingType != "base64" {
6969
c.Sugar.Errorw("Invalid encoding type specified", zap.String("encodingType", encodingType))
70-
return nil, fmt.Errorf("invalid encoding type: %s. Must be 'raw' or 'base64'", encodingType)
70+
return nil, fmt.Errorf("invalid encoding type: %s. Must be 'byte' for rawBytes or 'base64' for base64 encoded content", encodingType)
7171
}
7272

7373
if method != http.MethodPost && method != http.MethodPut {
@@ -215,7 +215,17 @@ func createStreamingMultipartRequestBody(files map[string][]string, formDataFiel
215215
}
216216

217217
// addFilePartWithEncoding adds a file part to the multipart writer with specified encoding.
218-
// Supports both raw file content and base64 encoding based on encodingType parameter.
218+
// Parameters:
219+
// - writer: The multipart writer used to construct the request body
220+
// - fieldName: The name of the form field for this file part
221+
// - filePath: Path to the file to be uploaded
222+
// - fileContentTypes: Map of content types for each file field
223+
// - formDataPartHeaders: Map of custom headers for each form field
224+
// - encodingType: The encoding to use ('byte' for raw bytes or 'base64' for base64 encoding)
225+
// - sugar: Logger for progress and debug information
226+
//
227+
// Returns:
228+
// - error: Any error encountered during the file part creation or upload process
219229
func addFilePartWithEncoding(writer *multipart.Writer, fieldName, filePath string, fileContentTypes map[string]string, formDataPartHeaders map[string]http.Header, encodingType string, sugar *zap.SugaredLogger) error {
220230
file, err := os.Open(filePath)
221231
if err != nil {
@@ -264,6 +274,15 @@ func addFilePartWithEncoding(writer *multipart.Writer, fieldName, filePath strin
264274
}
265275

266276
// createFilePartHeader creates the MIME header for a file part with the specified encoding type.
277+
// Parameters:
278+
// - fieldname: The name of the form field
279+
// - filename: The name of the file being uploaded
280+
// - contentType: The content type of the file
281+
// - customHeaders: Additional headers to include in the part
282+
// - encodingType: The encoding being used ('byte' or 'base64')
283+
//
284+
// Returns:
285+
// - textproto.MIMEHeader: The constructed MIME header for the file part
267286
func createFilePartHeader(fieldname, filename, contentType string, customHeaders http.Header, encodingType string) textproto.MIMEHeader {
268287
header := textproto.MIMEHeader{}
269288
header.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`, fieldname, filepath.Base(filename)))

0 commit comments

Comments
 (0)