尝试将图像上传到firebase存储时出现以下错误:
PlatformException(Error -13000, FIRStorageErrorDomain, An unknown error occurred, please check the server response.)
它很奇怪,因为我从Android设备调用完全相同的功能时没有收到此错误。当我调用该函数时:
Future saveToStorage(File image) async {
FirebaseStorage.instance.setMaxOperationRetryTimeMillis(10);
storageReference = FirebaseStorage.instance.ref().child("AllUsers").child(uuid).child(imageFileName);
final StorageUploadTask uploadTask = storageReference.putFile(image, const StorageMetadata(contentLanguage: "en"));
await uploadTask.future.then( (UploadTaskSnapshot snapshot) { // hangs at this line
if (snapshot.downloadUrl != null) {
String downloadUrl = snapshot.downloadUrl.toString();
final fireImage = new FireImage(imageFileName, currentDateTime, imageCount, downloadUrl);
storage.deleteImageFile(imageFileName);
saveToDatabase(fireImage);
instance.setInt("ImageCount", imageCount + 1);
} else {
saveFile(image);
}
})
}
代码在点await uploadTask.future.then( etc
处挂起,然后出现上述错误。
更新1:
我刚刚注意到这个错误[Generic] Creating an image format with an unknown type is an error
更新2: 现在出现此错误:
[] __nwlog_err_simulate_crash_libsystem libsystem simulate crash unavailable "libsystem_network.dylib: nw_host_stats_add_src :: received error for SRC_ADDED: [22] Invalid argument"
[] nw_host_stats_add_src received error for SRC_ADDED: [22] Invalid argument, dumping backtrace:
[x86_64] libnetcore-856.1.8
0 libsystem_network.dylib 0x0000000115e4480e __nw_create_backtrace_string + 123
1 libsystem_network.dylib 0x0000000115e5b358 nw_get_host_stats + 1083
2 libnetwork.dylib 0x000000011712aca9 nw_endpoint_resolver_start_next_child + 1382
3 libdispatch.dylib 0x0000000115bcc810 _dispatch_call_block_and_release + 12
4 libdispatch.dylib 0x0000000115bee12e _dispatch_client_callout + 8
5 libdispatch.dylib 0x0000000115bd3523 _dispatch_queue_serial_drain + 1018
6 libdispatch.dylib 0x0000000115bd3cf3 _dispatch_queue_invoke + 1118
7 libdispatch.dylib 0x0000000115bd5a0e _dispatch_root_queue_drain + 506
8 libdispatch.dylib 0x0000000115bd57b4 _dispatch_worker_thread3 + 113
9 libsystem_pthrea
任何人都可以看到为什么我只在ios上出现此错误?
答案 0 :(得分:0)
我解决这个问题的方法是调用final url = (await uploadTask.future).downloadUrl;
并检查downloadUrl是否为null,调用是以这种方式进行的。如果你能看到其他很好的工作方法。
Future saveToStorage(File image) async {
FirebaseStorage.instance.setMaxUploadRetryTimeMillis(100)
final StorageReference ref = FirebaseStorage.instance.ref().child("AllUsers").child(uuid).child(imageFileName);
final StorageUploadTask uploadTask = ref.putFile(image, const StorageMetadata(contentLanguage: "en"));
print("Saving to storage here with file: $image");
final url = (await uploadTask.future).downloadUrl;
print("uploading image: $image");
if (url != null) {
print("got here with url");
String downloadUrl = url.toString();
final fireImage = new FireImage(imageFileName, currentDateTime, imageCount, downloadUrl);
storage.deleteImageFile(imageFileName);
print('download URL: $downloadUrl');
saveToDatabase(fireImage);
instance.setInt("ImageCount", imageCount + 1);
} else {
print("got here without url");
saveFile(image);
}
}