I am trying to upload a picture to Firebase storage in a Flutter app.
The error message I got back is that the User don't have the permission to Upload. In my Storage rules the permission is set to read and write when auth != null
.
I can load images from the Storage with the download url. Also I print out the FirebaseAuth current user and it is set. If i set the Firebase Storage Rules to allow everything (without Auth) it works.
Do I need to exlicitly pass the auth user somewhere? The auth is handled by the provider package within the app.
Error:
E/StorageException(17300): at com.google.firebase.storage.UploadTask.shouldContinue(com.google.firebase:firebase-storage@@17.0.0:309)
E/StorageException(17300): at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@17.0.0:226)
E/StorageException(17300): at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@17.0.0:1106)
E/StorageException(17300): at com.google.firebase.storage.StorageTask$$Lambda$10.run(Unknown Source:2)
E/StorageException(17300): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
E/StorageException(17300): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
E/StorageException(17300): at java.lang.Thread.run(Thread.java:764)
E/StorageException(17300): Caused by: java.io.IOException: { "error": { "code": 403, "message": "Permission denied. Could not perform this operation" }}
E/StorageException(17300): at com.google.firebase.storage.network.NetworkRequest.parseResponse(com.google.firebase:firebase-storage@@17.0.0:455)
E/StorageException(17300): at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(com.google.firebase:firebase-storage@@17.0.0:435)
E/StorageException(17300): at com.google.firebase.storage.network.NetworkRequest.processResponseStream(com.google.firebase:firebase-storage@@17.0.0:426)
E/StorageException(17300): at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@17.0.0:280)
E/StorageException(17300): at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@17.0.0:294)
E/StorageException(17300): at com.google.firebase.storage.UploadTask.send(com.google.firebase:firebase-storage@@17.0.0:470)
E/StorageException(17300): at com.google.firebase.storage.UploadTask.uploadChunk(com.google.firebase:firebase-storage@@17.0.0:429)
E/StorageException(17300): at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@17.0.0:225)
E/StorageException(17300): ... 5 more
Code:
Future<void> changeProfilePicture(File _image, User user) async {
print(await FirebaseAuth.instance.currentUser());
final StorageReference _storageReference =
FirebaseStorage().ref().child(user.id);
final StorageUploadTask _uploadTask = _storageReference.putFile(_image);
StorageTaskSnapshot snap = await _uploadTask.onComplete;
String downloadUrl = await snap.ref.getDownloadURL();
print(downloadUrl);
user.setProfilePictureURL(downloadUrl);
Firestore.instance
.collection('users')
.document(user.id)
.setData(user.toMap());
}
Firebase Storage Rules;
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if auth != null;
}
}
}
dependencies:
dependencies:
flutter:
sdk: flutter
camera: ^0.5.4+2
path_provider: ^1.3.0
path: ^1.6.4
geolocator: ^5.1.3
firebase_core: ^0.4.0+9
firebase_auth: ^0.14.0+5
cloud_firestore: ^0.12.9+5
firebase_storage: ^3.0.6
provider: ^3.1.0
intl: ^0.16.0
according to the Firebase error page does the error code means that the Sender ID is different to the token ID. I tried different User Accounts its for all the same result.
SENDER_ID_MISMATCH (HTTP error code = 403) The authenticated sender ID is different from the sender ID for the registration token.