以 GUID 作为图像名称的新记录上传困境
对于我的 CMS,我希望用户能够上传连接到产品的图片。这一切都很顺利,直到有人想在创建新记录时上传图片。
这里的问题是,每个产品都有一个 GUID(紧邻 ProductID (PK)),并将在第一次保存产品时创建。我通过带有 Uploadify jquery 插件的网络服务上传我的图像,所以这一切都是基于 ajax 的方式。然而,图像上传器需要知道 GUID 才能将其存储在正确的目录中。
我的临时解决方案是让用户在上传之前保存产品,以便知道 GUID,但这对用户来说不是很友好,我确信会有更好的方法,但我自己找不到令人满意的方法。
这是我能想到的唯一选项,这还不错,但也许我完全错过了一些东西:
- 创建一个 GUID 而不保存产品,这样就可以上传图像,然后可以保存带有 GUID 的产品。但如果用户上传后离开怎么办?我也许可以创建一个计划任务来删除这些孤立图像
有人处理过类似的情况吗?我对您对他的问题的看法非常感兴趣,因为此功能将在我的 CMS 的多个部分中使用。
感谢您抽出时间!
亲切的问候, 标记
For my CMS I want users to be able to upload pictures which connect to a product. This all goes well until someone wants to upload a picture when creating a new record.
The problem here is that every product has a GUID (next to the ProductID (PK)) and will be created when the product is saved for the first time. I'm uploading my images trough a webservice with Uploadify jquery plugin so it's all in an ajax based way. The image uploader however needs to know the GUID to store it in the right directory.
My temporary fix was to just let the user save the product before uploading so the GUID is known but it's not very user friendly and I'm sure there would be a better way but I cannot find a satisfying one myself.
This is the only option which I could come up with which is kinda ok but maybe I'm missing something completely:
- Create a GUID without saving the product, so the image can be uploaded and the product with the GUID can be saved afterwards. But what if the user navigates away after uploading? I could maybe create a scheduled task to delete those orphant images
Has anyone dealt with similar scenarios? I'm very interested in your opions about his matter since this functionality will be used in multiple sections in my CMS.
Thanks for your time!
Kind regards,
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您主要是自己回答了您的问题。
关键是临时文件。这里有一个更聪明的方法:将图像保存在临时文件夹中,并记住
Session
对象中的图像名称。如果用户离开,请在 Global.asax 的Session_End
方法中删除这些图像(更好的说法是垃圾收集)。如果用户保存产品,则永久存储图像并相应命名!
You mostly answered your question by yourself.
The key are temporary files. Here is a little smarter method: save image in a temporary folder and remember the image name in
Session
object. If the user navigates away, in theSession_End
method of Global.asax, delete those images (better said garbage-collect them).If the user saves the product, permanently store the images and name them accordingly!!