StatObject verifies if object exists, you have permission to access it and returns information about the object.
(ctx context.Context, bucketName, objectName string, opts StatObjectOptions)
| 59 | // StatObject verifies if object exists, you have permission to access it |
| 60 | // and returns information about the object. |
| 61 | func (c *Client) StatObject(ctx context.Context, bucketName, objectName string, opts StatObjectOptions) (ObjectInfo, error) { |
| 62 | // Input validation. |
| 63 | if err := s3utils.CheckValidBucketName(bucketName); err != nil { |
| 64 | return ObjectInfo{}, ErrorResponse{ |
| 65 | StatusCode: http.StatusBadRequest, |
| 66 | Code: InvalidBucketName, |
| 67 | Message: err.Error(), |
| 68 | } |
| 69 | } |
| 70 | if err := s3utils.CheckValidObjectName(objectName); err != nil { |
| 71 | return ObjectInfo{}, ErrorResponse{ |
| 72 | StatusCode: http.StatusBadRequest, |
| 73 | Code: XMinioInvalidObjectName, |
| 74 | Message: err.Error(), |
| 75 | } |
| 76 | } |
| 77 | headers := opts.Header() |
| 78 | if opts.Internal.ReplicationDeleteMarker { |
| 79 | headers.Set(minIOBucketReplicationDeleteMarker, "true") |
| 80 | } |
| 81 | if opts.Internal.IsReplicationReadyForDeleteMarker { |
| 82 | headers.Set(isMinioTgtReplicationReady, "true") |
| 83 | } |
| 84 | |
| 85 | // Execute HEAD on objectName. |
| 86 | resp, err := c.executeMethod(ctx, http.MethodHead, requestMetadata{ |
| 87 | bucketName: bucketName, |
| 88 | objectName: objectName, |
| 89 | queryValues: opts.toQueryValues(), |
| 90 | contentSHA256Hex: emptySHA256Hex, |
| 91 | customHeader: headers, |
| 92 | }) |
| 93 | defer closeResponse(resp) |
| 94 | if err != nil { |
| 95 | return ObjectInfo{}, err |
| 96 | } |
| 97 | |
| 98 | if resp != nil { |
| 99 | deleteMarker := resp.Header.Get(amzDeleteMarker) == "true" |
| 100 | replicationReady := resp.Header.Get(minioTgtReplicationReady) == "true" |
| 101 | if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent { |
| 102 | if resp.StatusCode == http.StatusMethodNotAllowed && opts.VersionID != "" && deleteMarker { |
| 103 | errResp := ErrorResponse{ |
| 104 | StatusCode: resp.StatusCode, |
| 105 | Code: MethodNotAllowed, |
| 106 | Message: s3ErrorResponseMap[MethodNotAllowed], |
| 107 | BucketName: bucketName, |
| 108 | Key: objectName, |
| 109 | } |
| 110 | return ObjectInfo{ |
| 111 | VersionID: resp.Header.Get(amzVersionID), |
| 112 | IsDeleteMarker: deleteMarker, |
| 113 | }, errResp |
| 114 | } |
| 115 | return ObjectInfo{ |
| 116 | VersionID: resp.Header.Get(amzVersionID), |
| 117 | IsDeleteMarker: deleteMarker, |
| 118 | ReplicationReady: replicationReady, // whether delete marker can be replicated |