Flutter Fire - [Firebase Storage] W/NetworkRequest( 5624): no auth token for request

Viewed 204

My flutter app has a download feature that displays pdf from firebase storage and a download button to download the file. The view pdf function is working fine. However, the download pdf throws an exception

W/StorageUtil( 5624): no auth token for request
D/EGL_emulation( 5624): app_time_stats: avg=107.69ms min=6.46ms max=1118.11ms count=13
W/StorageUtil( 5624): Error getting App Check token; using placeholder token instead. Error: com.google.firebase.FirebaseException: Too many attempts.
E/StorageException( 5624): An unknown error occurred, please check the HTTP result code and inner exception for server response.
E/StorageException( 5624): User does not have permission to access this object.
E/StorageException( 5624):  Code: -13021 HttpResult: 403
E/StorageException( 5624): {  "error": {    "code": 403,    "message": "Permission denied."  }}

Details about the app:-

  1. The App does not have authentication (Feature not required so far)
  2. The storage rules in firebase storage is open to all users. match /documents/{docId}{allow read,write;}
  3. App check not enabled or enforced. All requests are allowed to the storage bucket so far.

The sample code that I am trying to download the file is

Future<void> downloadFile(String downloadUrl, String filename) async {
    Directory appDocDir = await getApplicationDocumentsDirectory();
    File downloadToFile = File('${appDocDir.path}/$filename');

    try {
      var url = await firebase_storage.FirebaseStorage.instance
          .ref('documents/$filename')
          .storage
          .ref();
      await url.writeToFile(downloadToFile);
    } on firebase_core.FirebaseException catch (e) {
     print('Exception' + e);
    }
  }

I have updated all the packages & dependencies but in vain. I am sure that I am missing something. A helping hand will be greatly appreciated.

1 Answers

Try:

final isRef = await firebase_storage.FirebaseStorage.instance
      .ref().child("'documents/$filename'");

Directory appDocDir = await getApplicationDocumentsDirectory();
File downloadToFile = File('${appDocDir.path}/$filename');

final downloadTask = isRef.writeToFile(downloadToFile);
Related