开发者

How should I approach this file upload issue?

开发者 https://www.devze.com 2023-03-25 04:48 出处:网络
I let users to upload photos. User can upload multiple photos at once using flash mechanism. User may try to upload same file twice or more times.

I let users to upload photos.

User can upload multiple photos at once using flash mechanism. User may try to upload same file twice or more times.

Ideally user should not have same photo twice. This may flood the system.

How do I prevent the user from uploading duplicate files?

What is the right approach to handle this? Will I prevent user letting upload duplicate files? Currently I am checking each file if user has it using ajax WS call. But user won't upload duplicate file that often, but the cost for check is always.

OR

I can avoid the costly checking and c开发者_开发技巧heck during saving only?

OR

Save user file with differnt name?

Just trying to see how would someone else do this.

Thanks


If you save using a guid for the name to can be sure you are never going to copy over an existing file

or

To reduce the cost of the file check, cache your file data using something like Enlib saving the Name, Size, etc. that way you can do a quick check to see if the data matches vs calling the system.IO to check your files


Let the users upload the file into a temporary area. When the file is uploaded, compute the hash of the file using MD5 or similar algorithim. Look up the hash in your data store. To reduce the chance of collision, the lookup could include the hash and user name of the user uploading the file.

If the hash already exists, the file has already been uploaded, so essentially the file can be removed from the temp area.

If the hash is not found, then the file can be added to the system.

If the hash can be computed and checked before the upload process begins, that is even better and the user doesn't waste time uploading.

Please note zero length files will produce the same hash, so a check should be done to make sure the file is valid.

0

精彩评论

暂无评论...
验证码 换一张
取 消