英文:
how to get only one object from a bucket?
问题
我需要一次只获取一个S3存储桶中的对象。我只找到了获取存储桶中所有对象的API,有没有办法只获取一个对象?我将使用特定的位置或索引来一次获取一个对象。
result, err := w.Client.ListObjectsV2(ctx, input)
if err != nil {
fmt.Println("获取对象时出错:")
fmt.Println(err)
}
for _, item := range result.Contents {
fmt.Println("名称:", *item.Key)
fmt.Println("最后修改时间:", *item.LastModified)
fmt.Println("大小:", item.Size)
fmt.Println("存储类别:", item.StorageClass)
fmt.Println("")
}
英文:
I need to get only one object at a time from S3 bucket..
And I only found the API to get all the objects in a bucket.. is there a way to get only one?
I'm gonna use a certain position or index to get one object at a time.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
result, err := w.Client.ListObjectsV2(ctx, input)
if err != nil {
fmt.Println("Got an error retrieving objects:")
fmt.Println(err)
}
for _, item := range result.Contents {
fmt.Println("Name: ", *item.Key)
fmt.Println("Last modified: ", *item.LastModified)
fmt.Println("Size: ", item.Size)
fmt.Println("Storage class: ", item.StorageClass)
fmt.Println("")
}
<!-- end snippet -->
答案1
得分: 2
你可以在ListObjectsV2Input中指定MaxKeys=1来请求返回的S3键的最大数量:
> MaxKeys:设置响应中返回的键的最大数量。默认情况下,该操作最多返回1,000个键名。响应可能包含较少的键,但绝不会超过该数量。
要获取下一个S3键,您可以在后续的ListObjectsV2请求中使用StartAfter
或ContinuationToken
。
英文:
You can request a maximum number of S3 keys to be returned by indicating MaxKeys=1 in your ListObjectsV2Input:
> MaxKeys: Sets the maximum number of keys returned in the response. By default the action returns up to 1,000 key names. The response might contain fewer keys but will never contain more.
To get the next S3 key, you would use either StartAfter
or ContinuationToken
in your subsequent ListObjectsV2 request.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论