@@ -33,15 +33,26 @@ type InitiateMultipartUploadResult struct {
3333//
3434// https://www.qcloud.com/document/product/436/7746
3535func (s * ObjectService ) InitiateMultipartUpload (ctx context.Context , name string , opt * InitiateMultipartUploadOptions ) (* InitiateMultipartUploadResult , * Response , error ) {
36+ var buff bytes.Buffer
3637 var res InitiateMultipartUploadResult
3738 sendOpt := sendOptions {
3839 baseURL : s .client .BaseURL .BucketURL ,
3940 uri : "/" + encodeURIComponent (name ) + "?uploads" ,
4041 method : http .MethodPost ,
4142 optHeader : opt ,
42- result : & res ,
43+ result : & buff ,
4344 }
4445 resp , err := s .client .doRetry (ctx , & sendOpt )
46+ if err == nil {
47+ err = xml .Unmarshal (buff .Bytes (), & res )
48+ if err != nil {
49+ // xml body存在非法字符(key存在非法字符)
50+ if _ , ok := err .(* xml.SyntaxError ); ok {
51+ err = UnmarshalInitMultiUploadResult (buff .Bytes (), & res )
52+ return & res , resp , err
53+ }
54+ }
55+ }
4556 return & res , resp , err
4657}
4758
@@ -233,20 +244,31 @@ func (o ObjectList) Less(i, j int) bool { // rewrite the Less method from small
233244// https://www.qcloud.com/document/product/436/7742
234245func (s * ObjectService ) CompleteMultipartUpload (ctx context.Context , name , uploadID string , opt * CompleteMultipartUploadOptions ) (* CompleteMultipartUploadResult , * Response , error ) {
235246 u := fmt .Sprintf ("/%s?uploadId=%s" , encodeURIComponent (name ), uploadID )
247+ var buff bytes.Buffer
236248 var res CompleteMultipartUploadResult
237249 sendOpt := sendOptions {
238250 baseURL : s .client .BaseURL .BucketURL ,
239251 uri : u ,
240252 method : http .MethodPost ,
241253 optHeader : opt ,
242254 body : opt ,
243- result : & res ,
255+ result : & buff ,
244256 }
245257 resp , err := s .client .doRetry (ctx , & sendOpt )
246258 // If the error occurs during the copy operation, the error response is embedded in the 200 OK response. This means that a 200 OK response can contain either a success or an error.
247259 if err == nil && resp .StatusCode == 200 {
260+ err = xml .Unmarshal (buff .Bytes (), & res )
261+ if err != nil {
262+ // xml body存在非法字符(key存在非法字符)
263+ if _ , ok := err .(* xml.SyntaxError ); ok {
264+ err = UnmarshalCompleteMultiUploadResult (buff .Bytes (), & res )
265+ if err != nil {
266+ return & res , resp , err
267+ }
268+ }
269+ }
248270 if res .ETag == "" {
249- return & res , resp , errors . New ("response 200 OK, but body contains an error" )
271+ return & res , resp , fmt . Errorf ("response 200 OK, but body contains an error, %v" , buff . Bytes () )
250272 }
251273 }
252274 return & res , resp , err
0 commit comments