![](/img/trans.png)
[英]when I run my app on localhost am able to display images on html but when I deploy to a cloud platform am getting 404 for the images
[英]Relative File Paths not getting detected when I deploy my app to Google Cloud platform
在本地一切正常,但是一旦我将我的应用程序部署到 App Engine。 谷歌云没有获取相对文件路径
根据Where to put your static files ,
您必须将 static 提供的文件放在应用的 webapp 目录中。 您可以使用文件夹,但请记住所有文件路径和 URI 都是相对于 webapp 目录的。
为 static 文件选择位置后,您必须使用元素在 appengine-web.xml 文件中定义它们的位置。
一个如何配置的例子是:
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<threadsafe>true</threadsafe>
<runtime>java8</runtime>
<static-files>
<include path="/**.html" >
</include>
</static-files>
</appengine-web-app>
此外,在文档中:[直接从您的应用提供文件]( https://cloud.google.com/appengine/docs/standard/java11/serving-static-files#serving_from_your_application ),它提到:
要在标准环境中为 Java 11 提供 static 文件,请使用 static_dir 或 static_file 元素在 app.yaml 文件中定义处理程序。
例如,以下行指示浏览器加载main.css
文件:
<link type="text/css" rel="stylesheet" href="/static/css/main.css">
./public
目录在项目的app.yaml
文件的static_dir
元素中定义:
handlers:
- url: /favicon\.ico
static_files: favicon.ico
- url: /static
static_dir: public
- url: /.*
secure: always
redirect_http_response_code: 301
script: auto
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.