MCPcopy
hub / github.com/minio/minio-go / copyObjectPartDo

Method copyObjectPartDo

api-compose-object.go:342–390  ·  view source on GitHub ↗
(ctx context.Context, srcBucket, srcObject, destBucket, destObject, uploadID string,
	partID int, startOffset, length int64, metadata map[string]string,
)

Source from the content-addressed store, hash-verified

340}
341
342func (c *Client) copyObjectPartDo(ctx context.Context, srcBucket, srcObject, destBucket, destObject, uploadID string,
343 partID int, startOffset, length int64, metadata map[string]string,
344) (p CompletePart, err error) {
345 headers := make(http.Header)
346
347 // Set source
348 headers.Set("x-amz-copy-source", s3utils.EncodePath(srcBucket+"/"+srcObject))
349
350 if startOffset < 0 {
351 return p, errInvalidArgument("startOffset must be non-negative")
352 }
353
354 if length >= 0 {
355 headers.Set("x-amz-copy-source-range", fmt.Sprintf("bytes=%d-%d", startOffset, startOffset+length-1))
356 }
357
358 for k, v := range metadata {
359 headers.Set(k, v)
360 }
361
362 queryValues := make(url.Values)
363 queryValues.Set("partNumber", strconv.Itoa(partID))
364 queryValues.Set("uploadId", uploadID)
365
366 resp, err := c.executeMethod(ctx, http.MethodPut, requestMetadata{
367 bucketName: destBucket,
368 objectName: destObject,
369 customHeader: headers,
370 queryValues: queryValues,
371 })
372 defer closeResponse(resp)
373 if err != nil {
374 return p, err
375 }
376
377 // Check if we got an error response.
378 if resp.StatusCode != http.StatusOK {
379 return p, httpRespToErrorResponse(resp, destBucket, destObject)
380 }
381
382 // Decode copy-part response on success.
383 cpObjRes := copyObjectResult{}
384 err = xmlDecoder(resp.Body, &cpObjRes)
385 if err != nil {
386 return p, err
387 }
388 p.PartNumber, p.ETag = partID, cpObjRes.ETag
389 return p, nil
390}
391
392// uploadPartCopy - helper function to create a part in a multipart
393// upload via an upload-part-copy request

Callers 1

CopyObjectPartMethod · 0.80

Calls 7

executeMethodMethod · 0.95
EncodePathFunction · 0.92
errInvalidArgumentFunction · 0.85
httpRespToErrorResponseFunction · 0.85
closeResponseFunction · 0.70
xmlDecoderFunction · 0.70
SetMethod · 0.45

Tested by

no test coverage detected