[英]change the mime-type of particular static files in tornado web
我的/ static / dir服務器端有一堆文件,名稱如下:
Slide0.html Slide121.html Slide143.html Slide165.html Slide187.html Slide208.html
Slide28.html Slide4.html Slide71.html Slide93.html
Slide100.html Slide122.html Slide144.html Slide166.html Slide188.html Slide209.html
然后我在同一個域上獲取它們並定期將它們插入iframe,他們只是渲染一些圖像,但是瀏覽器給出了以下錯誤:
Resource interpreted as Image but transferred with MIME type text/html: "http://localhost:8888/static/Slide66.html".
我試圖將staticfilehandler子類化為徒勞:
class StaticHandler(tornado.web.StaticFileHandler):
def get(self, path):
abspath = os.path.abspath(os.path.join(self.root, path))
mime_type, encoding = mimetypes.guess_type(abspath)
if mime_type:
self.set_header("Content-Type", mime_type)
if 'Slide' in abspath:
self.set_header('Content-Type',"image/jpg" )
但錯誤仍然存在我如何調整它?
在Tornado 3.1中,您可以get_content_type()
StaticFileHandler
並覆蓋get_content_type()
。
class StaticJSONFileHandler(tornado.web.StaticFileHandler):
def get_content_type(self):
return 'application/json'
問題是您的瀏覽器正在獲取“Slide66.html”以用作圖像。 您可能會使用“Slide66.html”作為“src”屬性生成具有“img”標記的HTML。
龍卷風正在做正確的事情。 如果“Slide66.html”確實是一個圖像,那么它應該是“Slide66.jpg”。 如果它是真正的HTML,那么它不能是圖像的“src”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.