开发者

Loading Files in AppEngine

开发者 https://www.devze.com 2022-12-26 11:04 出处:网络
I\'ve got a tiny bit of code to display a file in app.yaml - url: /(.*\\.(gif|png|jpg)) static_files: static/\\1

I've got a tiny bit of code to display a file

in app.yaml

- url: /(.*\.(gif|png|jpg))
  static_files: static/\1
  upload: static/(.*\.(gif|png|jpg))

in main.py

...
class ShowImage(webapp.RequestHandler):
  def get(self):
      rootpath = os.path.dirname(__file__)
      file = rootpath + "/static/tracker.gif";
      fh=open(file, 'r')
      self.response.out.write(fh.read())
      fh.close 
...

I can see the files 开发者_StackOverflow社区gone up by going to my *.appspot.com/tracker.gif (as per the app.yaml) But using *.appspot.com/showimage returns

Traceback (most recent call last):
  File "/base/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 510, in __call__
    handler.get(*groups)
  File "/base/data/home/apps/APPNAME/2.341131266814384624/main.py", line 170, in get
    fh=open(file, 'r')
IOError: [Errno 2] No such file or directory: '/base/data/home/apps/APPNAME/2.341131266814384624/static/tracker.gif'


Removed

- url: /(.*\.(gif|png|jpg))
  static_files: static/\1
  upload: static/(.*\.(gif|png|jpg))

from app.yaml apparently you cant serve content from folders you daftly marked as static

As from Deployment of static directory contents to google app engine


To spell out what Chris M. is referring to:

When deploying your application, any files matching an "upload" property for a "static_files" handler end up in a totally different place from your code and related files. As far as your code is concerned, they have been removed from the path you expect them to be at.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号