资源被解释为图像,但使用MIME类型text / html appengine进行了转移

I can't load images into a page after updating for the new version of go appengine. I don't know what I'm missing, but it used to be pretty straight forward before. I'm able to compile the code, but when I launch the app on the browser I'm getting the message:

Resource interpreted as Image but transferred with MIME type text/html: http://[...]/img/myimg.jpg

My app is as simple as this:

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

hello.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)
}

The documentation says: "Each file is served using the MIME type that corresponds with its filename extension unless overridden by the directory's mime_type setting", however it does not make a difference whether or not I define the mime_type in the app.yaml file.

There are many related questions on this forum but I couldn't find any answer that could effectively solve the issue.

Just as a note, I've tried with different images (jpg and png) to make sure it wasn't a issue with the image itself. I also deployed the same app (html and image) to apache webserver and it works fine.

You app.yaml is wrong, your img handler should be first, at the moment img/myimg.jpg will be handled by your main app handler, hence the text/html response.

Remember handlers are matched in the order they are defined and your main handler will catch everything if you use /.* as your regex.

Also your image tag should be absolute otherwise if you have more than one page deep you relative img path will be appended to the page.