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

Method copyObjectPartDo

api-compose-object.go:324–372  ·  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

322}
323
324func (c *Client) copyObjectPartDo(ctx context.Context, srcBucket, srcObject, destBucket, destObject, uploadID string,
325 partID int, startOffset, length int64, metadata map[string]string,
326) (p CompletePart, err error) {
327 headers := make(http.Header)
328
329 // Set source
330 headers.Set("x-amz-copy-source", s3utils.EncodePath(srcBucket+"/"+srcObject))
331
332 if startOffset < 0 {
333 return p, errInvalidArgument("startOffset must be non-negative")
334 }
335
336 if length >= 0 {
337 headers.Set("x-amz-copy-source-range", fmt.Sprintf("bytes=%d-%d", startOffset, startOffset+length-1))
338 }
339
340 for k, v := range metadata {
341 headers.Set(k, v)
342 }
343
344 queryValues := make(url.Values)
345 queryValues.Set("partNumber", strconv.Itoa(partID))
346 queryValues.Set("uploadId", uploadID)
347
348 resp, err := c.executeMethod(ctx, http.MethodPut, requestMetadata{
349 bucketName: destBucket,
350 objectName: destObject,
351 customHeader: headers,
352 queryValues: queryValues,
353 })
354 defer closeResponse(resp)
355 if err != nil {
356 return p, err
357 }
358
359 // Check if we got an error response.
360 if resp.StatusCode != http.StatusOK {
361 return p, httpRespToErrorResponse(resp, destBucket, destObject)
362 }
363
364 // Decode copy-part response on success.
365 cpObjRes := copyObjectResult{}
366 err = xmlDecoder(resp.Body, &cpObjRes)
367 if err != nil {
368 return p, err
369 }
370 p.PartNumber, p.ETag = partID, cpObjRes.ETag
371 return p, nil
372}
373
374// uploadPartCopy - helper function to create a part in a multipart
375// 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