Flatter图像上载-FIRStorageErrorDomain出现Firebase存储错误:根证书不受信任
我正试图通过Flitter应用程序中的iphone模拟器将图像上传到Firebase存储 我上传的代码是:Flatter图像上载-FIRStorageErrorDomain出现Firebase存储错误:根证书不受信任,firebase,flutter,firebase-storage,Firebase,Flutter,Firebase Storage,我正试图通过Flitter应用程序中的iphone模拟器将图像上传到Firebase存储 我上传的代码是: try { FirebaseStorage _storage = FirebaseStorage.instance; File image = await ImagePicker.pickImage(source: ImageSource.gallery);
try {
FirebaseStorage _storage = FirebaseStorage.instance;
File image =
await ImagePicker.pickImage(source: ImageSource.gallery);
String filename = path.basename(image.path);
StorageReference reference = _storage.ref().child("images/");
StorageUploadTask uploadTask = reference.putFile(
image);
final StorageTaskSnapshot downloadUrl =
(await uploadTask.onComplete);
final String url = (await downloadUrl.ref.getDownloadURL());
print('URL Is $url');
setState(() {
_images.add(url);
});
} catch (e) {
print("Error received $e");
}
我正在使用版本
firebase_存储:^3.1.3
我收到以下错误
{
type = error;
value = "Root certificate is not trusted.";
} )
"LocalDataTask <0EE7042E-6F74-4086-BC11-B6953C86BB09>.<1>" ), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <0EE7042E-6F74-4086-BC11-B6953C86BB09>.<1>, NSLocalizedDescription=cancelled}
{
类型=错误;
value=“根证书不受信任。”;
} )
“LocalDataTask.”,_nsurlerErrorFailingUrlSessiontaskerWorkey=LocalDataTask.,NSLocalizedDescription=cancelled}
我仔细查看了一下,发现有一个旧的bug看起来很相似,但是已经解决了,因为我使用的是新版本。我还看到一个关于这个的旧Stackoverflow帖子,他们建议注销并重新登录。。。我也做过。我不确定这个错误意味着什么,已经走到了死胡同。我能做些什么来解决这个问题
我在收到错误信息
StorageUploadTask uploadTask=reference.putFile(
图像)
您需要使用
HttpOverrides
绕过证书颁发
创建一个扩展HttpOverrides的类:
class _HttpOverrides extends HttpOverrides {
@override
HttpClient createHttpClient(SecurityContext context) {
final HttpClient client = super.createHttpClient(context);
client.badCertificateCallback = (X509Certificate cert, String host, int port) => true;
return client;
}
}
然后在main.dart给全班同学打电话
void main() {
HttpOverrides.global = _HttpOverrides();
runApp(App());
}
}
参考:使用此方法将图像上载到存储器并获取下载url:-
Future<String> _uploadFileToFirebase(String path, File file) async {
StorageReference reference = FirebaseStorage.instance.ref().child(path);
StorageUploadTask task = reference.putFile(file);
return await (await task.onComplete).ref.getDownloadURL();
}
Future\u上传文件到Firebase(字符串路径,文件)异步{
StorageReference=FirebaseStorage.instance.ref().child(路径);
StorageUploadTask任务=reference.putFile(文件);
return await(await task.onComplete).ref.getDownloadURL();
}