Good way to deal with this kind of issue is to have another domain/subdomain/(or even CDN service) that is dedicated to serving static files (images, scripts, stylesheets, documents, etc).
So for example in simple web applications:
Application path: /www/app/, Static files path: /www/static/
when user uploads a file, saving it to /www/static/complex/folder/structure/file.ext, and then save details about this uploaded file to your database.
and then serving the file trought static.my-amazing-web.app
What this will enable you to do is: easily leverage the users browser cache, do optimizations on the fly, scale out with CDN's when things start to get out of hand, and all kinds of fun stuff.
This will also enable you to implement more security for the files the users upload.
It is also good idea to have static file server that has execution of the files blocked, to improve the security of the server from malicious user uploads.