具有相同名称的 AWS S3 文件不会被覆盖,但会在文件名末尾添加字符

AWS S3 file with same name does not get overwrite but gets characters added at the end of filename

下面是我的场景示例,

  1. 我有一个 Django API 允许用户将图像上传到特定目录,图像将存储在 S3 存储桶中。假设文件名为 'example.jpeg'
  2. 用户再次上传同名图片'example.jpeg'到同一目录。
  3. 它们都正确地显示在同一目录中,但第二个在文件名末尾有额外的字符,如下所示 'example_785PmrM.jpeg'。我怀疑额外的字符是由 s3 添加的,但我的研究表明 s3 将覆盖同名文件。

如何启用覆盖功能,我还没有看到任何选项。

谢谢

S3 本身不会自行更改密钥。我看到的唯一可能对此产生影响的选项是 Django's storage backend for S3:

AWS_S3_FILE_OVERWRITE (optional: default is True)

By default files with the same name will overwrite each other. Set this to False to have extra characters appended.

所以您应该将 AWS_S3_FILE_OVERWRITE 设置为 True 以防止这种行为。

根据您的具体需要,考虑 enabling S3 versioning 以便您可以访问以前版本的对象,因为它们将来会在 S3 中被覆盖。