Flask: Provide a "media" route

Created on 2 Nov 2017  路  7Comments  路  Source: pallets/flask

Similar to the static route, add configuration and a route to serve uploaded files. Default to os.path.join(app.instance_path, 'uploads') and /media/<path:filename>. I've observed new developers thinking they should place user uploads in the static folder, which is not a good pattern (since that would be modifying package assets). A separate media folder will hopefully help with this.

Most helpful comment

Not sure if it is needed. I always create the routes to upload media into S3 or Google Storage.

All 7 comments

Not sure if that's useful to have built-in. I'd rather improve the docs and make it clear that uploaded files should go somewhere else...

@ThiefMaster i think its a good idea to have something like this as a opt out, since it removes a pretty nasty mistake vector for beginners - it also should be noted that not everyone is keen on the docs - features that when misused pose a security risk should be set up in a way that by default you dont create a risk

Django does this (but that's not justification on its own :wink:). This seems natural since you're always going to need a way to serve / generate urls for saved uploads. I always end up writing this route.

Not sure if it is needed. I always create the routes to upload media into S3 or Google Storage.

I don't think it is a good idea to have a built-in media route which is not useful for production.

@davidism can we close it?

I always end up writing this route.

In this case, you can create an extension for it.

Yeah, I think that's a better idea.

@lepture perhaps this would fit in your Flask-Storage extension?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rkomorn picture rkomorn  路  3Comments

sungjinp11 picture sungjinp11  路  3Comments

ghostbod99 picture ghostbod99  路  4Comments

tomjaguarpaw picture tomjaguarpaw  路  3Comments

westonplatter picture westonplatter  路  3Comments