Dart 未处理的异常:[firebase_storage/unknown] 位置不应是完整的 URL
Posted
技术标签:
【中文标题】Dart 未处理的异常:[firebase_storage/unknown] 位置不应是完整的 URL【英文标题】:Dart Unhandled Exception: [firebase_storage/unknown] location should not be a full URL 【发布时间】:2021-06-20 16:38:06 【问题描述】:我尝试使用插件 https://pub.dev/packages/flutter_cache_manager_firebase 来缓存我保存在 firebase 存储中的音频,其 url 为
https://firebasestorage.googleapis.com/v0/b/ocwa-app.appspot.com/o/142-1624205564448.aac?alt=media&token=b06a7cf9-5050-43ad-b5e9-60c4eda85b54
当我将 url 传递给方法时
file = await FirebaseCacheManager().getSingleFile(widget.url);
它会在控制台中引发错误
E/flutter (32343): [ERROR:flutter/shell/common/shell.cc(103)] Dart Unhandled Exception: [firebase_storage/unknown] location should not be a full URL., stack trace: #0 MethodChannelReference.getDownloadURL (package:firebase_storage_platform_interface/src/method_channel/method_channel_reference.dart:59:7)
E/flutter (32343): <asynchronous suspension>
E/flutter (32343): #1 FirebaseHttpFileService.get (package:flutter_cache_manager_firebase/src/firebase_http_file_service.dart:12:16)
E/flutter (32343): <asynchronous suspension>
E/flutter (32343): #2 WebHelper._updateFile (package:flutter_cache_manager/src/web/web_helper.dart:99:22)
E/flutter (32343): <asynchronous suspension>
E/flutter (32343): #3 WebHelper._downloadOrAddToQueue (package:flutter_cache_manager/src/web/web_helper.dart:67:7)
E/flutter (32343): <asynchronous suspension>
请告诉我如何将正确的 url 传递给参数。我使用的当前网址是从
返回的downloadUrlFuture uploadAudio() async
final uploadTimestamp = DateTime.now().millisecondsSinceEpoch;
setState(()
fileName =
getImageFileName(G.loggedInId.toString(), '$uploadTimestamp');
fileName = fileName + '.aac';
);
Reference reference = FirebaseStorage.instance.ref().child(fileName);
TaskSnapshot uploading;
uploading = await reference.putFile(
File(recordingFile), SettableMetadata(contentType: 'audio/aac'));
return uploading.ref.getDownloadURL();
【问题讨论】:
【参考方案1】:您需要从 URL 中删除方案。
你可以这样做:
final String url = widget.url;
final Uri uri = Uri.parse(url);
final urlWithoutScheme = url.replaceFirst('$uri.scheme://', '');
///Pass it to the getSingleFile method
file = await FirebaseCacheManager().getSingleFile(urlWithoutScheme);
下面的代码是从https://github.com/firebase/firebase-android-sdk/blob/master/firebase-storage/src/main/java/com/google/firebase/storage/FirebaseStorage.java 抛出错误的地方。
if (lowerCaseLocation.startsWith("gs://")
|| lowerCaseLocation.startsWith("https://")
|| lowerCaseLocation.startsWith("http://"))
throw new IllegalArgumentException("location should not be a full URL.");
【讨论】:
以上是关于Dart 未处理的异常:[firebase_storage/unknown] 位置不应是完整的 URL的主要内容,如果未能解决你的问题,请参考以下文章
错误:flutter/lib/ui/ui_dart_state.cc(148) 未处理的异常
Dart 未处理的异常:[firebase_storage/unknown] 位置不应是完整的 URL
怎么解决?颤振(6629):[错误:颤振/lib/ui/ui_dart_state.cc(209)]未处理的异常:NoSuchMethodError
无法将车辆信息保存到 firebase [VERBOSE-2:ui_dart_state.cc(186)] 未处理异常:无效参数:“TextEditingController”实例
错误:flutter/lib/ui/ui_dart_state.cc(177) 未处理的异常:NoSuchMethodError:方法“插入”在 null 上调用
如何解决此问题 [错误:flutter/lib/ui/ui_dart_state.cc(199)] 未处理的异常:NoSuchMethodError:getter 'phone' 被调用为 null。