AWS SDK for Goを使って、S3のバケット内の画像情報を取得してみる

ListObjectsの使用例

svc := s3.New(session.New())

params := &s3.ListObjectsInput{
    Bucket:       aws.String("BucketName"), // Required
    Delimiter:    aws.String("Delimiter"),
    EncodingType: aws.String("EncodingType"),
    Marker:       aws.String("Marker"),
    MaxKeys:      aws.Int64(1),
    Prefix:       aws.String("Prefix"),
}
resp, err := svc.ListObjects(params)

if err != nil {
    // Print the error, cast err to awserr.Error to get the Code and
    // Message from an error.
    fmt.Println(err.Error())
    return
}

// Pretty-print the response data.
fmt.Println(resp)

http://docs.aws.amazon.com/sdk-for-go/api/service/s3/S3.html#ListObjects-instance_method

ListObjectsInputの各パラメーター

  • Bucket(*string)
required
  • Marker(*string)
Specifies the key to start with when listing objects in a bucket.
  • EncodingType(*string enum)
Requests Amazon S3 to encode the object keys in the response and specifies the encoding method to use.  
An object key may contain any Unicode character;  
however, XML 1.0 parser cannot parse some characters, such as characters with an ASCII value from 0 to 10.  
For characters that are not supported in XML 1.0,
you can add this parameter to request that Amazon S3 encode the keys in the response.

Enum Values:
s3.EncodingTypeUrl = "url"
  • Delimiter(*string)
A delimiter is a character you use to group keys.

※Keyを絞り込むときに使います
※CommonPrefix内に絞り込んだ結果が返却されます

  • MaxKeys(*int64)
Sets the maximum number of keys returned in the response. 
The response might contain fewer keys but will never contain more.

※指定しなれば1000になります

  • Prefix(*string)
Limits the response to keys that begin with the specified prefix.

※バケット内の特定のディレクトリ配下のみ絞込んで取得したいときに使用します

http://docs.aws.amazon.com/sdk-for-go/api/service/s3.html#type-ListObjectsInput