listObjectsV2Query - (List Objects V2) - List some or all (up to 1000) of the objects in a bucket. You can use the request parameters as selection criteria to return a subset of the objects in a bucket. request parameters :- --------- ?prefix - Limits the response to keys that begin with the specif
(ctx context.Context, bucketName, objectPrefix, continuationToken string, fetchOwner, metadata bool, delimiter, startAfter string, maxkeys int, headers http.Header)
| 210 | // ?start-after - Sets a marker to start listing lexically at this key onwards. |
| 211 | // ?max-keys - Sets the maximum number of keys returned in the response body. |
| 212 | func (c *Client) listObjectsV2Query(ctx context.Context, bucketName, objectPrefix, continuationToken string, fetchOwner, metadata bool, delimiter, startAfter string, maxkeys int, headers http.Header) (ListBucketV2Result, error) { |
| 213 | // Validate bucket name. |
| 214 | if err := s3utils.CheckValidBucketName(bucketName); err != nil { |
| 215 | return ListBucketV2Result{}, err |
| 216 | } |
| 217 | // Validate object prefix. |
| 218 | if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil { |
| 219 | return ListBucketV2Result{}, err |
| 220 | } |
| 221 | // Get resources properly escaped and lined up before |
| 222 | // using them in http request. |
| 223 | urlValues := make(url.Values) |
| 224 | |
| 225 | // Always set list-type in ListObjects V2 |
| 226 | urlValues.Set("list-type", "2") |
| 227 | |
| 228 | if metadata { |
| 229 | urlValues.Set("metadata", "true") |
| 230 | } |
| 231 | |
| 232 | // Set this conditionally if asked |
| 233 | if startAfter != "" { |
| 234 | urlValues.Set("start-after", startAfter) |
| 235 | } |
| 236 | |
| 237 | // Always set encoding-type in ListObjects V2 |
| 238 | urlValues.Set("encoding-type", "url") |
| 239 | |
| 240 | // Set object prefix, prefix value to be set to empty is okay. |
| 241 | urlValues.Set("prefix", objectPrefix) |
| 242 | |
| 243 | // Set delimiter, delimiter value to be set to empty is okay. |
| 244 | urlValues.Set("delimiter", delimiter) |
| 245 | |
| 246 | // Set continuation token |
| 247 | if continuationToken != "" { |
| 248 | urlValues.Set("continuation-token", continuationToken) |
| 249 | } |
| 250 | |
| 251 | // Fetch owner when listing |
| 252 | if fetchOwner { |
| 253 | urlValues.Set("fetch-owner", "true") |
| 254 | } |
| 255 | |
| 256 | // Set max keys. |
| 257 | if maxkeys > 0 { |
| 258 | urlValues.Set("max-keys", fmt.Sprintf("%d", maxkeys)) |
| 259 | } |
| 260 | |
| 261 | // Execute GET on bucket to list objects. |
| 262 | resp, err := c.executeMethod(ctx, http.MethodGet, requestMetadata{ |
| 263 | bucketName: bucketName, |
| 264 | queryValues: urlValues, |
| 265 | contentSHA256Hex: emptySHA256Hex, |
| 266 | customHeader: headers, |
| 267 | }) |
| 268 | defer closeResponse(resp) |
| 269 | if err != nil { |
no test coverage detected