我需要从S3下载文件,然后将同一文件上传到其他S3存储桶中。到目前为止,我有:
sess := session.Must(session.NewSession())
downloader := s3manager.NewDownloader(sess)
buffer := aws.NewWriteAtBuffer([]byte{})
n, err := downloader.Download(buffer, &s3.GetObjectInput{
Bucket: aws.String(sourceS3Bucket),
Key: aws.String(documentKey),
})
uploader := s3manager.NewUploader(sess)
result, err := uploader.Upload(&s3manager.UploadInput{
Bucket: aws.String(targetS3Bucket),
Key: aws.String(documentKey),
Body: buffer,
})
根据这里的答案,我使用了aws.WriteAtBuffer:https://stackoverflow.com/a/48254996/504055
但是,我目前仍停留在如何将该缓冲区视为实现io.Reader接口的东西上,这正是上载者的Upload方法所需要的。
答案 0 :(得分:3)
使用bytes.NewReader在bytes in the buffer上创建io.Reader:
List components = dadosJson["result"]["address_components"];
final items = components
.where((item) =>
item["types"].contains("administrative_area_level_1") ||
item["types"].contains("administrative_area_level_2"))
.toList();
items.forEach((item) => print(item["short_name"]));