2011-09-12 45 views
2

我在GAE上託管我的Unity3d Web應用程序時出現問題。 當應用程序負載和網絡播放器開始要求「.unity3d」文件,我用下面的python腳本,使HTTP響應:Unity3d - Google App Engine上的主機

class UnityHandler(webapp.RequestHandler): 
    def get (self, q): 
    if q is None: 
     q = 'WebPlayer.unity3d' 

path = os.path.join (os.path.dirname (__file__), q) 
self.response.headers ['Content-Type'] = 'text/html' 
self.response.out.write (template.render (path, {})) 

def main(): 
    application = webapp.WSGIApplication (
    [('/(.*html)?', MainHandler), 
    ('/(.*unity3d)?', UnityHandler) 
    ], debug=True) 
    util.run_wsgi_app (application) 

它不工作得非常好,它發現該文件,但Unity網絡播放器給我一個「壞文件長度」的錯誤。

那麼誰能告訴我問題在哪裏? 我認爲它與設置「內容類型」有關,但我不知道如何解決它?

感謝,

薩默爾薩米

回答

3

我要去承擔,第一,你的意思是縮進3條線開始path =

其次,我猜你的意圖是將URL「/」路由到WebPlayer.unity3d。然而,你的兩個正則表達式都會匹配/因爲斜槓後面的所有內容都是可選的; MainHandler將從第一個接收請求。

第三,它看起來像你試圖不僅通過動態處理程序而且通過模板引擎提供靜態文件。爲什麼?如果您只是想逐字提供靜態文件,請使用static handlers

假設你已經放置在一個名爲靜態目錄中.unity3d文件:

# render WebPlayer.unity3d on/
- url:/
    static_files: static/WebPlayer.unity3d 
    upload: static/WebPlayer.unity3d 

# match other .unity3d files 
- url: /(.*\.unity3d) 
    static_files: static/\1 
    upload: static/(.*\.unity3d) 

# match *.html and anything else 
- url: .* 
    script: main.py 
+0

謝謝,它的工作,我用這樣的: '處理器: #匹配.unity3d文件 - 網址: /(static/webplayer.unity3d) static_files:static/webplayer.unity3d upload:static/webplayer.unity3d mime_type:application/vnd.unity' –