Из документации Firebase я нашел этот getReferenceUrl (url) метод. Я использую этот gs: //app_id.appspot.com/users/0a7d99409c.jpg в качестве параметра внутри метода getReferenceUrl.
/// Creates a [StorageReference] given a gs:// or // URL pointing to a Firebase
/// Storage location.
Future<StorageReference> getReferenceFromUrl(String fullUrl) async {
....
..
}
}
Вариант использования: Я загружаю файл в хранилище и сохраняю местоположение файла для дальнейшего использования. И когда мне нужно будет загрузить файл в будущем, как я могу использовать это местоположение сохраненного файла для загрузки этого конкретного файла? Я пробовал через этот код:
String fileLocation = 'gs://app_id.appspot.com/users/0a7d99409c.jpg';
FirebaseStorage storage = FireStorageService.getObject();
StorageReference storageReference = await storage.getReferenceFromUrl(fileLocation);
await storageReference.getDownloadURL().then((returnUrl) {
print(returnUrl);
print(returnUrl);
});
Сообщения об ошибках
Сообщение 1: Ошибка при получении токена java .util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: войдите в систему, прежде чем пытаться получить токен.
Сообщение 2: необработанное исключение: PlatformException (download_error, объект не существует в местоположении ., ноль)
E/StorageUtil(10404): error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.
W/NetworkRequest(10404): no auth token for request
E/StorageException(10404): StorageException has occurred.
E/StorageException(10404): Object does not exist at location.
E/StorageException(10404): Code: -13010 HttpResult: 404
E/StorageException(10404): { "error": { "code": 404, "message": "Not Found. Could not get object", "status": "GET_OBJECT" }}
E/StorageException(10404): java.io.IOException: { "error": { "code": 404, "message": "Not Found. Could not get object", "status": "GET_OBJECT" }}
/flutter (22431): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(download_error, Object does not exist at location., null)
E/flutter (22431): #0 StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:569
E/flutter (22431): #1 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:156
E/flutter (22431): <asynchronous suspension>
E/flutter (22431): #2 MethodChannel.invokeMethod
package:flutter/…/services/platform_channel.dart:329
E/flutter (22431): #3 StorageReference.getDownloadURL
package:firebase_storage/src/storage_reference.dart:142
E/flutter (22431): #4 _AboutState._uploadFile