Я получаю следующую ошибку при попытке загрузить изображение в хранилище 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?
Способ, которым ive решил эту проблему, - это вызвать 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);
}
}