E / StorageUtil (5389): ошибка при получении токена java .util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException - PullRequest
1 голос
/ 21 февраля 2020

Я пытаюсь загрузить файл в Firebase, и, по моему мнению, он не работает в следующих функциях. Если у кого-то из вас возникла подобная проблема при использовании Firebase для загрузки файлов, я был бы признателен, если бы вы могли поделиться своим решением. Спасибо

 void uploadFile() async {
    String fileName = basename(sampleFile.path);
    final StorageReference storageFileRef = FirebaseStorage.instance.ref().child(fileName);
    var timeKey = new DateTime.now();
    final StorageUploadTask uploadTask = storageFileRef.child(timeKey.toString() + ".pdf").putFile(sampleFile);
    StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
    var FileUrl = await (await uploadTask.onComplete).ref.getDownloadURL();
    url = FileUrl.toString();
    print("File url = $url");
    saveToDataBase(url);
  }

  void saveToDataBase(String url) {
    var dbTimeKey = new DateTime.now();
    var formatDate = new DateFormat('MMM d, yyyy');
    var formatTime = new DateFormat('EEEE, hh:mm: aaa');

    String date = formatDate.format(dbTimeKey);
    String time = formatTime.format(dbTimeKey);

    DatabaseReference ref = FirebaseDatabase.instance.reference();
    var data = {
      "file" : url,
      "description" : _myValue,
      "date" : date,
      "time" : time,
    };

    ref.child("Reports").push().set(data);

  }

Я получаю следующую ошибку. Я предоставил их и дальше. Ваша помощь очень ценится.

E/StorageUtil( 5389): error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.
W/NetworkRequest( 5389): no auth token for request
E/StorageException( 5389): StorageException has occurred.
E/StorageException( 5389): User does not have permission to access this object.
E/StorageException( 5389):  Code: -13021 HttpResult: 403

Правила, установленные в Firebase, показаны ниже, и анонимная аутентификация включена.

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if true;
    }
  }
}

Полный вывод показан ниже.

Launching lib\main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\apk\debug\app-debug.apk.
Syncing files to device Android SDK built for x86...
D/EGL_emulation( 5389): eglMakeCurrent: 0xa44b3440: ver 2 0 (tinfo 0xa449b370)
I/zygote  ( 5389): Do partial code cache collection, code=60KB, data=43KB
I/zygote  ( 5389): After code cache collection, code=60KB, data=43KB
I/zygote  ( 5389): Increasing code cache capacity to 256KB
W/IInputConnectionWrapper( 5389): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5389): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5389): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5389): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5389): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5389): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5389): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5389): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5389): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5389): endBatchEdit on inactive InputConnection
I/FilePicker( 5389): Checking permission: android.permission.READ_EXTERNAL_STORAGE
D/EGL_emulation( 5389): eglMakeCurrent: 0xa44b2e40: ver 2 0 (tinfo 0x869a6aa0)
D/FlutterView( 5389): Detaching from a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@cf568df
I/FilePicker( 5389): [SingleFilePick] File URI:content://com.google.android.apps.docs.storage/document/acc%3D1%3Bdoc%3D1
E/FilePickerUtils( 5389): Getting for API 19 or abovecontent://com.google.android.apps.docs.storage/document/acc%3D1%3Bdoc%3D1
I/zygote  ( 5389): Do full code cache collection, code=121KB, data=83KB
I/zygote  ( 5389): After code cache collection, code=106KB, data=61KB
E/FilePickerUtils( 5389): Document URI
I/FilePickerUtils( 5389): Caching file from remote/external URI
D/FlutterView( 5389): Attaching to a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@cf568df
D/EGL_emulation( 5389): eglCreateContext: 0xa44b3440: maj 2 min 0 rcv 2
D/EGL_emulation( 5389): eglMakeCurrent: 0xa44b3440: ver 2 0 (tinfo 0xa449b370)
D/EGL_emulation( 5389): eglMakeCurrent: 0xa44b2e40: ver 2 0 (tinfo 0x869a6aa0)
D/EGL_emulation( 5389): eglMakeCurrent: 0xa44b3440: ver 2 0 (tinfo 0xa449b370)
E/StorageUtil( 5389): error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.
D/NetworkSecurityConfig( 5389): No Network Security Config specified, using platform default
W/NetworkRequest( 5389): no auth token for request
I/zygote  ( 5389): Do partial code cache collection, code=110KB, data=71KB
I/zygote  ( 5389): After code cache collection, code=110KB, data=71KB
I/zygote  ( 5389): Increasing code cache capacity to 512KB
E/StorageException( 5389): StorageException has occurred.
E/StorageException( 5389): User does not have permission to access this object.
E/StorageException( 5389):  Code: -13021 HttpResult: 403
E/StorageException( 5389): The server has terminated the upload session
E/StorageException( 5389): java.io.IOException: The server has terminated the upload session
E/StorageException( 5389):  at 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...