将本地元数据可靠地关联到远程文件?
WinForms / C#
我的应用程序允许用户指定 1) 2) 给定文件的附加信息,这两个信息都会上传到服务器。 有两个独立的上传:首先是文件,然后(也许更)是元数据。
请假设该文件始终保持不变且可用(对于代码)。
上传元数据时,我需要确保它与其给定文件关联,而无需再次上传该文件(它们是大文件)。
我的计划是使用文件以下三个属性的 MD5 哈希值:
- 内容
- 大小
- 创建日期
该哈希值将伴随文件和元数据各自的上传(以及最终的持久性)。
我忽略了哪些更明智的解决方案?
WinForms / C#
My application allows the user to specify 1) additional information for 2) a given file, both of which are uploaded to the server. There are two isolated uploads: first the file, and (maybe much) later the metadata.
Please assume the file to be always unchanged and available (to the code).
When the metadata is uploaded, I need to ensure it is associated with its given file without again uploading that file (they're big files).
My plan is to use an MD5 hash of the following three attributes of the file:
- contents
- size
- created date
The hash will accompany both the file and the metadata in their respective uploads (and eventual persistence).
What smarter solution am I overlooking?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以考虑使用 SHA-1 甚至更好的 SHA-256 来代替 MD5,因为 MD5 哈希值可能不够唯一:可以生成大小和 MD5 哈希值与其他文件匹配的文件。 例如,请参阅 MD5 漏洞。
更新:如果文件唯一性并不严格重要,您可能会发现在上传过程中生成自动递增的 id 更方便。
You may consider using SHA-1 or even better SHA-256 instead of MD5, since MD5 hashes may not be unique enough: it is possible to generate a file with size and MD5 hash matching those of other file. See, for example, MD5 vulnerability.
Upd: if file uniqueness is not strictly important, you may find much more convenient to just generate an auto-incremented id during upload.