Home > Software design >  Firebase Storage Exception: User does not have permission to access this object
Firebase Storage Exception: User does not have permission to access this object

Time:03-19

I get the following error when upload image to the firebase storage.

plugins versions:

image_picker: ^0.6.7 3
firebase_storage: ^3.1.6
permission_handler: ^5.0.1 1

Firebase Storage rules:

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

And the full error I get in the debug console:

E/StorageException( 9672): StorageException has occurred.
E/StorageException( 9672): User does not have permission to access this object.
E/StorageException( 9672):  Code: -13021 HttpResult: 403
E/StorageException( 9672): The server has terminated the upload session
E/StorageException( 9672): java.io.IOException: The server has terminated the upload session
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.serverStateValid(com.google.firebase:firebase-storage@@17.0.0:340)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.shouldContinue(com.google.firebase:firebase-storage@@17.0.0:309)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@17.0.0:223)
E/StorageException( 9672):  at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@17.0.0:1106)
E/StorageException( 9672):  at com.google.firebase.storage.StorageTask$$Lambda$10.run(com.google.firebase:firebase-storage@@17.0.0)
E/StorageException( 9672):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
E/StorageException( 9672):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
E/StorageException( 9672):  at java.lang.Thread.run(Thread.java:761)
E/StorageException( 9672): Caused by: java.io.IOException: {  "error": {    "code": 403,    "message": "Permission denied."  }}
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.parseResponse(com.google.firebase:firebase-storage@@17.0.0:455)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(com.google.firebase:firebase-storage@@17.0.0:435)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.processResponseStream(com.google.firebase:firebase-storage@@17.0.0:426)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@17.0.0:280)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@17.0.0:294)
E/StorageException( 9672):  at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@17.0.0:70)
E/StorageException( 9672):  at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@17.0.0:62)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.sendWithRetry(com.google.firebase:firebase-storage@@17.0.0:476)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.beginResumableUpload(com.google.firebase:firebase-storage@@17.0.0:277)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@17.0.0:218)
E/StorageException( 9672):  ... 5 more
E/StorageException( 9672): StorageException has occurred.
E/StorageException( 9672): User does not have permission to access this object.
E/StorageException( 9672):  Code: -13021 HttpResult: 403
E/StorageException( 9672): The server has terminated the upload session
E/StorageException( 9672): java.io.IOException: The server has terminated the upload session
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.serverStateValid(com.google.firebase:firebase-storage@@17.0.0:340)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.shouldContinue(com.google.firebase:firebase-storage@@17.0.0:309)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@17.0.0:223)
E/StorageException( 9672):  at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@17.0.0:1106)
E/StorageException( 9672):  at com.google.firebase.storage.StorageTask$$Lambda$10.run(com.google.firebase:firebase-storage@@17.0.0)
E/StorageException( 9672):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
E/StorageException( 9672):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
E/StorageException( 9672):  at java.lang.Thread.run(Thread.java:761)
E/StorageException( 9672): Caused by: java.io.IOException: {  "error": {    "code": 403,    "message": "Permission denied."  }}
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.parseResponse(com.google.firebase:firebase-storage@@17.0.0:455)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(com.google.firebase:firebase-storage@@17.0.0:435)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.processResponseStream(com.google.firebase:firebase-storage@@17.0.0:426)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@17.0.0:280)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@17.0.0:294)
E/StorageException( 9672):  at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@17.0.0:70)
E/StorageException( 9672):  at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@17.0.0:62)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.sendWithRetry(com.google.firebase:firebase-storage@@17.0.0:476)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.beginResumableUpload(com.google.firebase:firebase-storage@@17.0.0:277)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@17.0.0:218)
E/StorageException( 9672):  ... 5 more
E/StorageException( 9672): StorageException has occurred.
E/StorageException( 9672): User does not have permission to access this object.
E/StorageException( 9672):  Code: -13021 HttpResult: 403
E/StorageException( 9672): The server has terminated the upload session
E/StorageException( 9672): java.io.IOException: The server has terminated the upload session
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.serverStateValid(com.google.firebase:firebase-storage@@17.0.0:340)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.shouldContinue(com.google.firebase:firebase-storage@@17.0.0:309)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@17.0.0:223)
E/StorageException( 9672):  at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@17.0.0:1106)
E/StorageException( 9672):  at com.google.firebase.storage.StorageTask$$Lambda$10.run(com.google.firebase:firebase-storage@@17.0.0)
E/StorageException( 9672):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
E/StorageException( 9672):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
E/StorageException( 9672):  at java.lang.Thread.run(Thread.java:761)
E/StorageException( 9672): Caused by: java.io.IOException: {  "error": {    "code": 403,    "message": "Permission denied."  }}
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.parseResponse(com.google.firebase:firebase-storage@@17.0.0:455)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(com.google.firebase:firebase-storage@@17.0.0:435)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.processResponseStream(com.google.firebase:firebase-storage@@17.0.0:426)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@17.0.0:280)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@17.0.0:294)
E/StorageException( 9672):  at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@17.0.0:70)
E/StorageException( 9672):  at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@17.0.0:62)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.sendWithRetry(com.google.firebase:firebase-storage@@17.0.0:476)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.beginResumableUpload(com.google.firebase:firebase-storage@@17.0.0:277)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@17.0.0:218)
E/StorageException( 9672):  ... 5 more
E/StorageException( 9672): StorageException has occurred.
E/StorageException( 9672): User does not have permission to access this object.
E/StorageException( 9672):  Code: -13021 HttpResult: 403
E/StorageException( 9672): The server has terminated the upload session
E/StorageException( 9672): java.io.IOException: The server has terminated the upload session
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.serverStateValid(com.google.firebase:firebase-storage@@17.0.0:340)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.shouldContinue(com.google.firebase:firebase-storage@@17.0.0:309)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@17.0.0:223)
E/StorageException( 9672):  at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@17.0.0:1106)
E/StorageException( 9672):  at com.google.firebase.storage.StorageTask$$Lambda$10.run(com.google.firebase:firebase-storage@@17.0.0)
E/StorageException( 9672):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
E/StorageException( 9672):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
E/StorageException( 9672):  at java.lang.Thread.run(Thread.java:761)
E/StorageException( 9672): Caused by: java.io.IOException: {  "error": {    "code": 403,    "message": "Permission denied."  }}
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.parseResponse(com.google.firebase:firebase-storage@@17.0.0:455)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(com.google.firebase:firebase-storage@@17.0.0:435)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.processResponseStream(com.google.firebase:firebase-storage@@17.0.0:426)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@17.0.0:280)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@17.0.0:294)
E/StorageException( 9672):  at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@17.0.0:70)
E/StorageException( 9672):  at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@17.0.0:62)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.sendWithRetry(com.google.firebase:firebase-storage@@17.0.0:476)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.beginResumableUpload(com.google.firebase:firebase-storage@@17.0.0:277)
E/StorageException( 9672):  at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@17.0.0:218)
E/StorageException( 9672):  ... 5 more
E/StorageException( 9672): StorageException has occurred.
E/StorageException( 9672): User does not have permission to access this object.
E/StorageException( 9672):  Code: -13021 HttpResult: 403
E/StorageException( 9672): {  "error": {    "code": 403,    "message": "Permission denied."  }}
E/StorageException( 9672): java.io.IOException: {  "error": {    "code": 403,    "message": "Permission denied."  }}
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.parseResponse(com.google.firebase:firebase-storage@@17.0.0:455)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(com.google.firebase:firebase-storage@@17.0.0:435)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.processResponseStream(com.google.firebase:firebase-storage@@17.0.0:426)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@17.0.0:280)
E/StorageException( 9672):  at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@17.0.0:294)
E/StorageException( 9672):  at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@17.0.0:70)
E/StorageException( 9672):  at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@17.0.0:62)
E/StorageException( 9672):  at com.google.firebase.storage.GetDownloadUrlTask.run(com.google.firebase:firebase-storage@@17.0.0:74)
E/StorageException( 9672):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
E/StorageException( 9672):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
E/StorageException( 9672):  at java.lang.Thread.run(Thread.java:761)
E/flutter ( 9672): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(download_error, User does not have permission to access this object., null, null)
E/flutter ( 9672): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter ( 9672): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
E/flutter ( 9672): <asynchronous suspension>
E/flutter ( 9672): #2      StorageReference.getDownloadURL (package:firebase_storage/src/storage_reference.dart:142:12)
E/flutter ( 9672): <asynchronous suspension>
E/flutter ( 9672): #3      FirebaseStorageService.uploadProductImage (package:farmers_market/src/services/firebase_storage_service.dart:14:12)
E/flutter ( 9672): <asynchronous suspension>
E/flutter ( 9672): #4      ProductBloc.pickImage (package:farmers_market/src/blocs/product_bloc.dart:95:24)
E/flutter ( 9672): <asynchronous suspension>
E/flutter ( 9672): 

and a piece of code

PickedFile image;
await Permission.photos.request();
var permissionStatus = await Permission.photos.status;
if (permissionStatus.isGranted) {

    image = await _picker.getImage(source: ImageSource.gallery);
    if (image != null) {
       var imageUrl = await storageService.uploadProductImage(
       File(image.path), uuid.v4());
       changeImageUrl(imageUrl)
    } else {
       print('No Path Received');
    }
} else {
    print('Grant Permissions and try again');
}

I succesfully authentificated the firebase service before that. I use Android and emulator to make it. What did I miss?

CodePudding user response:

In your Firebase rules,

allow read, write: if false;

means that it is not possible to read or write on your DB. You can change it to if true to test if this is the cause of your problem, and then use more accurate rules.

See Firestore rule if true or false

  • Related