英文:
How to remove dangling files in s3?
问题
我目前正在开发一个产品,其中如果用户在使用上传模态框上传文件后取消或关闭模态框而没有完成整个过程,那么文件就会变成孤立的。它没有在任何地方被使用,但我仍然必须永远在S3上存储和维护它。这些文件需要立即或定期清理,以便更有意义。有人能建议一种处理这种情况的方法吗?
例如,在上传模态框中,用户首先上传文件,然后应该输入一些字段,如名称等。上传文件后,它被存储在S3中。现在,如果用户决定不继续进行该过程(即不填写名称字段等),并且返回,那个文件仍然存在于S3中。
附注:已经在使用的文件在我的数据库中存储了它们的S3 URL。
英文:
I am currently working on a product wherein if a file is uploaded using upload modal and user cancel/closes the modal without completing the entire process, then it becomes orphaned. It's not being used anywhere but I still have to store and maintain it forever on s3. These files need to be cleaned up either immediately or periodically, whatever makes more sense. Can someone suggest a way of handling such a scenario?
Eg. In the upload modal, the user first uploads the file, and then is supposed to enter some fields such as Name, etc. On uploading the file, it gets stored in s3. Now, if the user decides not to go ahead with the process (i.e. filling in the Name field, etc) and backs-off, then that file is still in s3.
PS: Files which are being used have their s3 URL stored in my database.
答案1
得分: 1
你正在寻找带有一些标签的S3生命周期规则。
当用户开始上传时,请将刚刚上传的文件标记为PROCESSED: false
。然后创建一个生命周期规则,该规则在5天后删除具有标签PROCESSED: false
的文件。
用户完成的任何流程也需要更新标签为PROCESSED: true
,以便不删除好的文件。
生命周期规则可以通过存储桶设置的"管理"选项卡中找到。示例:
英文:
You're looking for S3 lifecycle rules with some tags.
When user starts the upload, tag the just uploaded file as example with PROCESSED: false
. Then create lifecycle rule which deletes files with tag PROCESSED: false
after 5 days lets say.
Any process that user will finish needs also to update the tag to PROCESSED: true
, so good files won't be deleted.
Lifecycle rules are available through the Management tab of your bucket settings. Example:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论