如何存储文件以便在 ASP.NET 中进行处理
Path.GetTempFileName 非常接近我想要的。但我不想重新启动机器并丢失这些文件(因为它们是临时文件)。我需要的是一个唯一的文件名。最好的方法是什么?我正在考虑将密钥插入数据库,让他们拉动它,但我认为这不是一个好主意。
我正在考虑使用随机数,但我总是担心在服务器上使用随机数。由于两个请求可以同时发生并获得相同的数字(假设我不锁定它,这会使其变慢)。那么,我能做什么呢?
我计划使用该文件名,以便我可以从用户发布请求中获取文件并将其保存到文件中。然后我将其放入要处理的队列中,如果出现问题,可能会立即处理,一秒钟后或几分钟/几小时内处理。
Path.GetTempFileName is pretty close to what i want. But i wouldnt want to restart the machine and lose these files (as they would be temp). What i need is a unique filename. Whats the best way to do it? I was thinking inserting a key into a db, commit them pulling it but i dont think its a good idea.
I was thinking of using a random number but i am always worried about using random numbers when on a server. Since two request can occur at the same time getting the same number (assuming i dont lock it which would make it slow). So, what can i do?
I plan to use the filename so i can take file(s) from the users post request and save them to a file. Which i then put into a queue to be processed which may be immediately, a second from now or minutes/hours if something has gone wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 GUID 存储文件名?
如果您期望有很多文件。我替换了 guid 破折号,使其成为目录结构。
变成
Store filenames using GUID?
If you are expecting a lot of files. I replace guid dashes to make it into a directory structure.
becomes
Guid 怎么样:
或者一些时间戳什么的:
How about a Guid:
or some timestamp or something: