亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 golang 的 AWS S3 并行下載

使用 golang 的 AWS S3 并行下載

Go
揚帆大魚 2023-06-05 09:18:45
我正在編寫一個函數,使用 aws-sdk for go 從 AWS S3 存儲桶下載一個大文件 (9GB)。我需要對此進行優化并快速下載文件。func DownloadFromS3Bucket(bucket, item, path string) {    os.Setenv("AWS_ACCESS_KEY_ID", constants.AWS_ACCESS_KEY_ID)    os.Setenv("AWS_SECRET_ACCESS_KEY", constants.AWS_SECRET_ACCESS_KEY)    file, err := os.Create(filepath.Join(path, item))    if err != nil {        fmt.Printf("Error in downloading from file: %v \n", err)        os.Exit(1)    }    defer file.Close()    sess, _ := session.NewSession(&aws.Config{        Region: aws.String(constants.AWS_REGION)},    )    downloader := s3manager.NewDownloader(sess)    numBytes, err := downloader.Download(file,        &s3.GetObjectInput{            Bucket: aws.String(bucket),            Key:    aws.String(item),        })    if err != nil {        fmt.Printf("Error in downloading from file: %v \n", err)        os.Exit(1)    }    fmt.Println("Download completed", file.Name(), numBytes, "bytes")}有人可以建議擴展此功能的解決方案。
查看完整描述

1 回答

?
GCT1015

TA貢獻1827條經驗 獲得超4個贊

嘗試將您的 NewDownLoader() 更改為此。

//?Create?a?downloader?with?the?session?and?custom?options
downloader?:=?s3manager.NewDownloader(sess,?func(d?*s3manager.Downloader)?{
?????d.PartSize?=?64?*?1024?*?1024?//?64MB?per?part
?????d.Concurrency?=?4})

可以用 d 設置的選項列表。

查看完整回答
反對 回復 2023-06-05
  • 1 回答
  • 0 關注
  • 421 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號