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

Method getObject

api-get-object.go:680–722  ·  view source on GitHub ↗

getObject - retrieve object from Object Storage. Additionally this function also takes range arguments to download the specified range bytes of an object. Setting offset and length = 0 will download the full object. For more information about the HTTP Range header. go to http://www.w3.org/Protocol

(ctx context.Context, bucketName, objectName string, opts GetObjectOptions)

Source from the content-addressed store, hash-verified

678// For more information about the HTTP Range header.
679// go to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.
680func (c *Client) getObject(ctx context.Context, bucketName, objectName string, opts GetObjectOptions) (io.ReadCloser, ObjectInfo, http.Header, error) {
681 // Validate input arguments.
682 if err := s3utils.CheckValidBucketName(bucketName); err != nil {
683 return nil, ObjectInfo{}, nil, ErrorResponse{
684 StatusCode: http.StatusBadRequest,
685 Code: InvalidBucketName,
686 Message: err.Error(),
687 }
688 }
689 if err := s3utils.CheckValidObjectName(objectName); err != nil {
690 return nil, ObjectInfo{}, nil, ErrorResponse{
691 StatusCode: http.StatusBadRequest,
692 Code: XMinioInvalidObjectName,
693 Message: err.Error(),
694 }
695 }
696
697 // Execute GET on objectName.
698 resp, err := c.executeMethod(ctx, http.MethodGet, requestMetadata{
699 bucketName: bucketName,
700 objectName: objectName,
701 queryValues: opts.toQueryValues(),
702 customHeader: opts.Header(),
703 contentSHA256Hex: emptySHA256Hex,
704 })
705 if err != nil {
706 return nil, ObjectInfo{}, nil, err
707 }
708 if resp != nil {
709 if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent {
710 return nil, ObjectInfo{}, nil, httpRespToErrorResponse(resp, bucketName, objectName)
711 }
712 }
713
714 objectStat, err := ToObjectInfo(bucketName, objectName, resp.Header)
715 if err != nil {
716 closeResponse(resp)
717 return nil, ObjectInfo{}, nil, err
718 }
719
720 // do not close body here, caller will close
721 return resp.Body, objectStat, resp.Header, nil
722}

Callers 3

FGetObjectMethod · 0.95
GetObjectMethod · 0.95
GetObjectMethod · 0.80

Calls 9

executeMethodMethod · 0.95
CheckValidBucketNameFunction · 0.92
CheckValidObjectNameFunction · 0.92
httpRespToErrorResponseFunction · 0.85
ToObjectInfoFunction · 0.85
closeResponseFunction · 0.70
ErrorMethod · 0.45
toQueryValuesMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected