I now there are a lot of questions about app.yaml, and I searched and searched, but this one I couldn't find.
TLDR: PLEASE read full answer first, this isn't your standard application_readable:true. I basically want to access the same file via different routes e.g. /static/img/pic.jpg AND /img/pic.jpg
USE CASE
I build a flask application (upon the work of fsouza ) and i try to build a thumbnail extension for flask which will work on gae (because it's a read-only FS, I forked flask-thumbnails and currently try to expand it.)
So I need:
- access to my static files via python so I can read the img and make thumbnails on the fly. URL is eg. /STATIC/IMG/PIC.JPG
- still deliver other images, css, js via app.yaml. URL is eg. /IMG/PIC.JPG
What's not working:
It's working locally, won't work after deploying. I thinks app.yaml is not so strictly enforced by dev_appserver.py as it should.
I can either get one of this scenarios to work. This is how my app.yaml currently looks:
builtins:
- appstats: on
- admin_redirect: on
- deferred: on
- remote_api: on
- url: /css
static_dir: application/static/css
- url: /js
static_dir: application/static/js
- url: /img
static_dir: application/static/img
- url: /static
static_dir: application/static
application_readable: true
- url: .*
script: run.application.app
I also tried this instead:
- url: /css/(.*)
static_files: css/\1
upload: css/(.*)
- url: /js/(.*)
static_files: js/\1
upload: js/(.*)
- url: /img/(.*)
static_files: img/\1
upload: img/(.*)
When I comment the specific js,css,img stuff out, the application can access the img in application/static/img and make a thumbnail out of it. But the urls with e.g. /img/dont.need.thumbnail.jpg won't be served.
When I comment this part:
- url: /static
static_dir: application/static
application_readable: true
img,css,js get served like they should.
Can anybody help me? What I'm doing wrong?
Are app.yaml urls recursive?
Current Workaround:
My current workaround is, that I simply add several url route through in python application. But that is not efficient and I suspect it costs me more CPU time and is slower. e.g.
app.add_url_rule('/img/<path>', 'static_img_files', view_func=views.static_img_files)
def static_img_files(path):
return static_files("img/"+path)
Bonus hint:
If you just git push-to-deploy
application_readable: true
won't work, so the python application won't have access to the static images as soon as you test it on the gae servers and not locally anymore. you have to deploy it via the app engine launcher (this alone took me ages to find out)
The answer is oh so simple: make every access path application_readable, because negative permissions are stronger than positive ones.
So kind of eat my own words, it is a simple case of application_readable:true :)