英文:
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"设置为以下内容,但出现错误:
- myBucket/myFolder
- myBucket/myFolder/
- 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
- myBucket/myFolder
- myBucket/myFolder/
- 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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论