Flutter打开Firebase存储下载url权限被拒绝403



我正在将应用程序中的PDF上传到Firebase Storage。

现在我想在浏览器中打开我的应用程序的PDF表单。为此,我尝试使用url_launcher,如下所示:

Future<void> _launchURL(
BuildContext context, {
required String url,
String? errorMessage,
}) async {
if (await canLaunch(url) == true) {
await launch(Uri.encodeFull(url));
}
}

但当打开URL时,我得到了这个:

{
"error": {
"code": 403,
"message": "Permission denied."
}
}

如果将我的Storage Rules设置为allow: read, write;,我会得到一个404-error。将我的launch更改为:时

Future<void> _launchURL(
BuildContext context, {
required String url,
String? errorMessage,
}) async {
if (await canLaunch(url) == true) {
await launch(url);  // <- without encoding
}
}

我得到了Platform-Exeption:

未处理的异常:PlatformException(错误,启动时出错https://firebasestorage.googleapis.com/v0/b/appflug.appspot.com/o/studs%2FladSXGLivhRtVlJh3vogjXoxCdj1%2FlanguageTest%2FwIcon.pdf?alt=media&token=403f9631-58ed-4931-b76c-b9e6253e7d25,null,null(

但它在网络上运行。它实际上也在我的iOS设备上打开了我浏览器中的PDF,但它抛出了exeption。。。

我错过了什么?如何在iOS、Android和Android上的浏览器中从Firebase Storage打开downloadUrl;网状物

这两种方法都适用于我使用https://pub.dev/packages/url_launcher使用版本6.1.0

Future<void> launchInWebViewWithoutJavaScript(String url) async {
final Uri toLaunch = Uri.parse(url);
if (!await launchUrl(
toLaunch,
mode: LaunchMode.inAppWebView,
webViewConfiguration: const WebViewConfiguration(enableJavaScript: false),
)) {
throw 'Could not launch $url';
}
}

然后你也可以使用这个:

Future<void> launchInWebViewOrVC(String url) async {
final Uri toLaunch = Uri.parse(url);
if (!await launchUrl(
toLaunch,
mode: LaunchMode.inAppWebView,
webViewConfiguration: const WebViewConfiguration(
headers: <String, String>{'my_header_key': 'my_header_value'}),
)) {
throw 'Could not launch $url';
}
}

最新更新