0

I don't know why in 2015 there's still tutorial about saving image to mysql using blob. As a beginner I used to do that but now I can foresee how terrible it is if you want to build a system that have people using it.

I just did an implementation moving to s3, but I'm not sure I'm doing it right or not. Says I'm building a blog system, each user will have their own blog. So how I save and retrieve images from s3 is using identifier in the url endpoint.

like alex have a blog post which is id of 123, so his image file will be .com/blog/123/hisfilehere.png

besides putting the identifier in the url, is therer any better way to do it? or it's the best way to do it? I also read about storing extra information along with the file to s3, but not sure how does that different than naming apart of the endpoint for identifier.

Nichole A. Miler
  • 1,281
  • 2
  • 11
  • 21

1 Answers1

0

The common practice is to use some hash (e.g. file MD5 hash, or randomly generated one) as filename and to create subdirectories using first (or last) chars of this hash. See this answer.

Community
  • 1
  • 1
kozlice
  • 714
  • 7
  • 12
  • 1
    @NicholeA.Miler Personally, I wouldn't involve the username in storage structure logic and stick with file's MD5, but it's up to you to choose. – kozlice Jan 06 '16 at 19:57