在s3中覆盖文件非常容易,每次上载都会在model表中添加一个新条目。这导致多个条目具有相同的文件名,我想避免这种情况。是否有任何提示可以更改这种行为,所以django不会添加新条目,而是会更新旧条目的字段?
protected_storage = storages.backends.s3boto3.S3Boto3Storage(
acl='private',
querystring_auth=True,
querystring_expire=120, # 2 minutes, try to ensure people won't/can't share
)
class DrawerFile(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE)
file = models.FileField(
null=False,
blank=False,
storage=protected_storage,
upload_to=file_location
)
谢谢!