【发布时间】:2014-05-20 19:04:36
【问题描述】:
更新新版本的 go appengine 后,我无法将图像加载到页面中。我不知道我错过了什么,但它以前很简单。 我能够编译代码,但是当我在浏览器上启动应用程序时,我收到了以下消息:
资源解释为图像,但使用 MIME 类型 text/html 传输:http://[...]/img/myimg.jpg
我的应用就是这么简单:
index.html
<!DOCTYPE html>
<html>
<title>Hello</title>
<head>
</head>
<body>
<h1>Welcome to my website</h1>
<img src="img/myimg.png" />
</body>
</html>
app.yaml
application: myapp
version: 1
runtime: go
api_version: go1
handlers:
- url: /.*
script: _go_app
- url: /img
static_dir: img
mime_type: image/jpg
你好.go
package hello
import (
"net/http"
"text/template"
)
func init() {
http.HandleFunc("/", handler)
}
func handler(w http.ResponseWriter, r *http.Request) {
template.Must(template.ParseFiles("index.html")).Execute(w, nil)
}
documentation 说:“每个文件都使用与其文件扩展名相对应的 MIME 类型提供服务,除非被目录的 mime_type 设置覆盖”,但无论是否我在 app.yaml 文件中定义了 mime_type。
这个论坛有很多相关问题,但我找不到任何可以有效解决问题的答案。
请注意,我已尝试使用不同的图像(jpg 和 png)来确保图像本身没有问题。我还将相同的应用程序(html 和图像)部署到 apache 网络服务器,它工作正常。
【问题讨论】:
标签: html google-app-engine go