Go – 下载以特定前缀的 S3 文件

huangapple go评论83阅读模式
英文:

Go - Download S3 file under a prefix

问题

我正在尝试下载一个位于目录下而不是直接在存储桶中的文件。

	file, err := os.Create("s3file.csv")
	downloader := s3manager.NewDownloader(session.New(&aws.Config{Region: aws.String("us-east-1")}))
	numBytes, err := downloader.Download(file,
		&s3.GetObjectInput{
			Bucket: aws.String(bucket),
			Key:    aws.String(key),
		})

存储桶名称 - "myBucket"
文件夹名称 - "myFolder"
文件名称 - "myFile"

GetObjectInput不接受前缀作为参数。
仅指定存储桶名称而不带前缀会导致"Key not found"错误。
尝试将"bucket"设置为以下内容,但出现错误:

  1. myBucket/myFolder
  2. myBucket/myFolder/
  3. myBucket&prefix=myFolder

错误:无法下载文件 SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.
状态码:403,请求ID:647D920C72888888

注意:直接在存储桶下下载文件是可以工作的。

英文:

I am trying to download a file that is under a directory instead of directly in a bucket.

	file, err := os.Create("s3file.csv")
	downloader := s3manager.NewDownloader(session.New(&aws.Config{Region: aws.String("us-east-1")}))
	numBytes, err := downloader.Download(file,
		&s3.GetObjectInput{
			Bucket: aws.String(bucket),
			Key:    aws.String(key),
		})

Bucket name - "myBucket"
Folder name - "myFolder"
file name - "myFile"

GetObjectInput doesn't accept Prefix as a parameter.
Specifying only bucket name without prefix is leading to Key not found error.
Tried setting "bucket" as following but got error

  1. myBucket/myFolder
  2. myBucket/myFolder/
  3. myBucket&prefix=myFolder

> Error: Failed to download file SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.
status code: 403, request id: 647D920C72888888

Note: Downloading a file directly under the bucket is working.

答案1

得分: 0

Bucket应该始终是您的存储桶名称。Key是对象的完整名称(路径),所以在您的情况下,应该是myFolder/myFile

英文:

Bucket should always be the name of your bucket. Key is the full name (path) of the object, so in your case, that should be myFolder/myFile.

huangapple
  • 本文由 发表于 2016年12月13日 03:48:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/41108412.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定