serve arbitrary static content on the fly with cherrypy -
i trying create media server using cherrypy , cant cherrypy serve files in directory isn't set @ startup in config. don't want expose drives root directory prefer expose directory @ time need it. there away this?
here relevant snippet of current code.
@cherrypy.expose def serve_mp3(self, mp3_path): #cherrypy.config.update({"media":{ #"tools.staticdir.on" : true, #"tools.staticdir.root" : "c:\\documents , settings\\sdc\\my documents\\my music", #"tools.staticdir.dir" : "", #"tools.staticfile.root" : "c:\\documents , settings\\sdc\\my documents\\my music" #}}) static_handler = cherrypy.tools.staticdir.handler(section="/media", dir="c:\\documents , settings\\sdc\\my documents\\my music") cherrypy.tree.mount(static_handler, '/media') mp3 = mp3_path.rsplit("\\",1)[1] return "media/" + urllib.quote(mp3)
thanks go cyraxjoe mess above wound being re-factored as
@cherrypy.expose def serve_mp3(self, mp3_path): mp3_path = urllib.unquote(mp3_path) return(cherrypy.lib.static.serve_file(mp3_path, content_type="audio/mpeg", disposition=none, name=none))
which worked fine serving audio tag. know exists front door access hdd first step , final result driven data base
i think should use functions serve static files directly instead of handler, fighting tool. direct call of functions can serve arbitrary path or file object if like.
Comments
Post a Comment