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)
| 678 | // For more information about the HTTP Range header. |
| 679 | // go to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35. |
| 680 | func (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 | } |
no test coverage detected