我按照 AWS 站点上的示例对文件进行 gzip 压缩并将它们流式传输到 S3,可在此处找到:http: //docs.aws.amazon.com/sdk-for-go/latest/v1/developerguide/common-examples.title。 html
我有一个问题,我的 S3 存储桶中唯一登陆的是基本上只有 GZIP 标头的文件。每个文件的大小为 23b。
知道什么会导致这种情况吗?
我的代码:
func (t *Table) Upload() {
year := time.Now().Format("2006")
month := time.Now().Format("01")
day := time.Now().Format("02")
reader, writer := io.Pipe()
go func() {
gw := gzip.NewWriter(writer)
io.Copy(gw, t.File)
t.File.Close()
gw.Close()
writer.Close()
}()
uploader := s3manager.NewUploader(session.New(&aws.Config{Region: aws.String(os.Getenv("AWS_REGION"))}))
result, err := uploader.Upload(&s3manager.UploadInput{
Body: reader,
Bucket: aws.String(os.Getenv("S3_BUCKET")),
Key: aws.String(fmt.Sprintf("%s/%s/%s/%s/%s", os.Getenv("S3_KEY"), year, month, day, t.Name+".csv.gz")),
})
if err != nil {
log.WithField("error", err).Fatal("Failed to upload file.")
}
log.WithField("location", result.Location).Info("Successfully uploaded to")
}
森林海
德玛西亚99
相关分类