Create a unique file name (hash) for user-uploaded images

I have a web application that allows users to upload images. I store the images in an S3 bucket and give them all the file names that are essentially the result of MD5 (session_id + unix_timestamp). Are there pitfalls of this method for creating unique image file names?

+5
source share
2 answers

I would think about saving files with some kind of folder format, since many S3-based S3 clients will work much better if there are no 200,000 files in one folder. It also does not hurt to add the correct extensions and mime type to the downloaded files. Thus, if you decide to serve them directly from S3 to a web page, etc., they will be ready to go.

2012/2 / 6gtbb88uytgfrses4.png

You can also put sizes in the name ...

2012/2 / 6gtbb88uytgfrses4_600x800_.png

+6
source

In terms of uniqueness, you should be safe. Collisions are unlikely (although possible) to occur when using MD5.

, , ( ). ? , GUID ( , - MD5), - .

+4

All Articles