如何修改/添加元数据到 System.Drawing.Image 文件
商业目的:我正在创建一个 CMS,并允许用户“删除”他们之前上传到服务器的图像。
问题:如果我允许他们真正删除图像,他们会留下用现在损坏的图像创建的旧帖子。示例:用户上传 vtWinsACC2005.jpg,写了一篇关于它的文章链接到该图像,然后最终清理了他的画廊并删除了该图像,但保留了该文章,最终得到了一篇图像损坏的文章。
目标:当用户“删除”他们之前上传的图像时,我想向 IO 中的实际文件添加一个“注释”字段或任何类型的元数据,例如, “hidden=true”,在我的 GetFiles() 逻辑中,我将检查以确保该元数据不存在。这样,用户就看不到他们已删除的图像,甚至可以在将来“恢复”他们不想删除的图像。当它们恢复时,我可以简单地擦除该文件中的元数据,仅此而已。
替代:在数据库中使用 userId + fileName 保留一个简单的查找表,并将其命名为“HiddenUserImage”,但是,上面的方法更有趣,如果我不必添加另一个表,那太好了!
有什么想法吗?这将在 C# 中进行。谢谢!
Business purpose: I'm creating a CMS, and allowing the user to "delete" images that they've previously uploaded to the server.
Issue: if I allow them to really delete the images, they are left with old posts they've created with now-broken images. Example: user uploads vtWinsACC2005.jpg, writes an article about it linking to the image, then finally cleans up his gallery and deletes that image, but leaves the article alone, ending up with an article with a broken image.
Goal: when a user "deletes" an image they've previously uploaded, I want to add a "note" field, or any type of meta data to the actual file in IO, with something like, "hidden=true," and in my GetFiles() logic, I'll check to make sure that that metadata does not exist. This way, the user doesn't see the images they've deleted, and they could even "restore" images in the future that they did not mean to delete. When they restore, I can simply wipe the metadata from that file, and that's it.
Alternative: keep a simple lookup table in the database with userId + fileName, and call it "HiddenUserImage," but, the above way is more fun, and if I don't have to add another table, then great!
Any ideas?? This will be in C#. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可以为每个图像创建一个 NTFS 备用数据流,这是一个映射到图像文件的隐藏 ADS 文件,并在其中存储 hide=true 属性。
I think you can create for each image a NTFS Alternate Data Stream, a hidden ADS file that is mapped to your image file and store there the hidden=true property.