@@ -30,13 +30,14 @@ func (g *GraphAPIHandler) MarshalRequest(body interface{}, method string, endpoi
3030 return data , nil
3131}
3232
33- // MarshalMultipartRequest creates a multipart request body with the provided form fields and files .
33+ // MarshalMultipartRequest encodes the request body as a multipart message for the Microsoft Graph API .
3434func (g * GraphAPIHandler ) MarshalMultipartRequest (fields map [string ]string , files map [string ]string , log logger.Logger ) ([]byte , string , string , error ) {
3535 body := & bytes.Buffer {}
3636 writer := multipart .NewWriter (body )
3737
3838 // Add the simple fields to the form data
3939 for field , value := range fields {
40+ log .Debug ("Adding field to multipart request" , zap .String ("Field" , field ), zap .String ("Value" , value ))
4041 if err := writer .WriteField (field , value ); err != nil {
4142 return nil , "" , "" , err
4243 }
@@ -55,6 +56,7 @@ func (g *GraphAPIHandler) MarshalMultipartRequest(fields map[string]string, file
5556 if err != nil {
5657 return nil , "" , "" , err
5758 }
59+ log .Debug ("Adding file to multipart request" , zap .String ("FormField" , formField ), zap .String ("FilePath" , filePath ))
5860 if _ , err := io .Copy (part , file ); err != nil {
5961 return nil , "" , "" , err
6062 }
@@ -68,7 +70,7 @@ func (g *GraphAPIHandler) MarshalMultipartRequest(fields map[string]string, file
6870 contentType := writer .FormDataContentType ()
6971 bodyBytes := body .Bytes ()
7072
71- // Extract the first and last parts of the body
73+ // Extract the first and last parts of the body for logging
7274 const logSegmentSize = 1024 // 1 KB
7375 bodyLen := len (bodyBytes )
7476 var logBody string
@@ -78,5 +80,10 @@ func (g *GraphAPIHandler) MarshalMultipartRequest(fields map[string]string, file
7880 logBody = string (bodyBytes [:logSegmentSize ]) + "..." + string (bodyBytes [bodyLen - logSegmentSize :])
7981 }
8082
83+ // Log the boundary and a partial body for debugging
84+ boundary := writer .Boundary ()
85+ log .Debug ("Multipart boundary" , zap .String ("Boundary" , boundary ))
86+ log .Debug ("Multipart request body (partial)" , zap .String ("Body" , logBody ))
87+
8188 return bodyBytes , contentType , logBody , nil
8289}
0 commit comments