我需要将文件上传到特定目录内的 S3 存储桶。我已经使用了 aws-sdk-go 包,并且能够使用存储桶中的 PutObject
函数上传文件。该文件将位于 bucket/root
目录中。
我需要做的是将它上传到 bucket/root/subDirectory
中,但我无法弄清楚这一点。
当前上传函数
_, s3Err := s3.New(s).PutObject(&s3.PutObjectInput{
Bucket: aws.String(envs.InitAWSEnvs().AWSS3Name),
Key: aws.String(fileDir),
ACL: aws.String("private"),
Body: bytes.NewReader(buffer),
ContentLength: aws.Int64(size),
ContentType: aws.String(http.DetectContentType(buffer)),
ContentDisposition: aws.String("attachment"),
ServerSideEncryption: aws.String("AES256"),
})
最佳答案
我想出了一个可能对很多人有用的不太常见的 gem,path.Join
函数。
主要是 PutObject
函数调用中 PutObjectInput
参数的 Key
对象的值为 aws.String(path .Join(path_to_directory, fileName)
而不是 aws.String(fileName)
关于go - 如何将文件上传到 S3 Bucket/目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57142035/