[英]How to upload an image file to Firebase Storage and show it in the Flutter web app
[英]Flutter Web how to serve file assetlinks.json for Android App Links verification
我正在Firebase Hosting上部署Flutter Web 應用程序。
以及Android 上的 Flutter 應用程序。
To use App Links that redirect to my Android application, I need to verify the App Links serving the file assetlinks.json
on the web at https://example.com/.well-known/assetlinks.json
如何在沒有 3XX 重定向的情況下從我的域(即部署在 web 上的 Flutter 和 firebase 托管)中提供文件?
如果我沒記錯的話,Firebase 將文件存儲在所謂的存儲桶中。 存儲桶可以直接暴露在互聯網上,或者您可以使用 API 提取您需要的文件並將其放在您的域中的某個公共位置:
https://firebase.google.com/docs/storage/web/list-files
要查看如何在 gloud 存儲桶中發布文件,這是一個很好的答案:
如何在 Google Cloud Storage 中公開許多文件?
請注意,所描述的方法提供了公共訪問權限,因此請確保您只公開您想要的內容。
將.well-know
文件夾和文件添加到 Flutter 項目的web
文件夾中就足夠了。
並更改firebase.json
添加標題和重寫條目。
{
"hosting": {
"public": "build/web",
"appAssociation": "NONE",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"headers": [
{
"source": "/.well-known/assetlinks.json",
"headers": [
{
"key": "Content-Type",
"value": "application/json"
}
]
}
],
"rewrites": [
{
"source": "/.well-known/assetlinks.json",
"destination": "/.well-known/assetlinks.json"
},
{
"source": "**",
"destination": "/index.html"
}
]
}
}
再次構建和部署,文件現在可以訪問了!
感謝https 的簡單指南://blog.bam.tech/developer-news/universal-links-firebase-hosting-and-flutter-web
Firebase 托管會在請求時自動生成assetlinks.json
和apple-app-site-association
文件。 它不需要任何額外的配置。
您只需要確保在 項目設置中正確設置了您的應用程序詳細信息(包、SHA256 證書指紋等),並確保在firebase.json
中將屬性appAssociation
設置為"AUTO"
(或省略,如AUTO
是默認值)。
示例firebase.json
:
{
"hosting": {
"public": "build/web",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"appAssociation": "AUTO",
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
參考: https://firebase.google.com/docs/hosting/full-config#rewrite-dynamic-links
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.