Go语言 AWS Batchdoor未从S3删除文件

k0pti3hp  于 2023-09-28  发布在  Go
关注(0)|答案(1)|浏览(100)

我不明白为什么有些文件已经从AWS S3 Bucket中删除,而有些文件没有。下面是我的删除函数:

func (s *S3Manager) Delete(keys []string) error {
    objects := make([]s3manager.BatchDeleteObject, len(keys))

    for i, v := range keys {
        objects[i] = s3manager.BatchDeleteObject{
            Object: &s3.DeleteObjectInput{
                Key:    aws.String(v),
                Bucket: s.bucket, // this is aws.String already
            },
        }
    }

    if err := s.remover.Delete(aws.BackgroundContext(), &s3manager.DeleteObjectsIterator{
        Objects: objects,
    }); err != nil {
        return err
    }

    return nil

}

保持不变-添加一些照片,然后尝试删除它们。一些照片删除完美,一些-不.也许有人可以帮我的建议吗?期待您的任何回复
更新:

func NewS3Manager(accessKeyID, secretAccessKey, region, bucket, assetsDomain string) (*S3Manager, error) {
    creds := credentials.Value{
        AccessKeyID:     accessKeyID,
        SecretAccessKey: secretAccessKey,
    }

    sess, err := session.NewSession(&aws.Config{
        Region:      aws.String(region),
        Credentials: credentials.NewStaticCredentialsFromCreds(creds),
    })
    if err != nil {
        return nil, fmt.Errorf("failed create aws session: %w", err)
    }

    return &S3Manager{
        remover:      s3manager.NewBatchDelete(sess),
        bucket:       aws.String(bucket),
    }, nil
}
ffscu2ro

ffscu2ro1#

你正在使用V1,也许你应该使用GO SDK的V2。由于没有批量删除,您必须通过范围。在此处运行包含版本删除的示例:https://github.com/megaproaktiv/s3deleteversion

相关问题