Firebase StorageException has occurred kotlin [duplicate] - firebase

I'm fairly new to Flutter and haven't ever used Firebase before so my aplogies if there is an obvious solution to this.
I'm working on a Flutter app which involves recording form submissions and submitting them to a central location.
Firebase Storage seemed like a good fit since as I understood it the app can upload files to the cloud bucket and then they can be accessed through the Firebase console. Correct me if I'm wrong.
So I found this module for Flutter;
https://pub.dartlang.org/packages/firebase_storage
I used the example code as a basis.
once at the start of the code I call;
final FirebaseApp app = await FirebaseApp.configure(
name: 'test',
options: new FirebaseOptions(
googleAppID: Platform.isIOS
? '{ios app id}'
: '{android app ID}',
gcmSenderID: '{project number code}',
apiKey: '{web api key from the firebase console}',
projectID: '{project ID}',
),
);
storage = new FirebaseStorage(
app: app, storageBucket: '{address to data bucket}');
Then to upload a file I've tried;
final StorageReference ref =
storage.ref().child('uploads').child(filename);
final StorageUploadTask uploadTask = ref.putFile(
file,
new StorageMetadata(
contentLanguage: 'en',
customMetadata: <String, String>{'activity': 'submission'},
),
);
final Uri downloadUrl = (await uploadTask.future).downloadUrl;
final http.Response downloadData = await http.get(downloadUrl);
final String name = await ref.getName();
final String bucket = await ref.getBucket();
final String path = await ref.getPath();
return downloadData.statusCode >= 200 && 299 >= downloadData.statusCode;
and in the Firebase console I created the Uploads folder and I think set everything else up correctly.
My Firebase storage access rules look like this;
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
My issue is that when I try to upload the file I get the following error;
W/DynamiteModule(25832): Local module descriptor class for com.google.android.gms.firebasestorage not found.
I/DynamiteModule(25832): Considering local module com.google.android.gms.firebasestorage:0 and remote module com.google.android.gms.firebasestorage:6
I/DynamiteModule(25832): Selected remote version of com.google.android.gms.firebasestorage, version >= 6
W/System (25832): ClassLoader referenced unknown path: /data/data/com.google.android.gms/app_chimera/m/00000040/n/armeabi-v7a
W/System (25832): ClassLoader referenced unknown path: /data/data/com.google.android.gms/app_chimera/m/00000040/n/armeabi
E/StorageUtil(25832): error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.
W/NetworkRequest(25832): no auth token for request
E/StorageException(25832): StorageException has occurred.
E/StorageException(25832): User does not have permission to access this object.
E/StorageException(25832): Code: -13021 HttpResult: 403
E/StorageException(25832): The server has terminated the upload session
E/StorageException(25832): java.io.IOException: The server has terminated the upload session
E/StorageException(25832): at com.google.firebase.storage.UploadTask.zzs(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.UploadTask.zzr(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.UploadTask.run(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.StorageTask.zzl(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.zzq.run(Unknown Source)
E/StorageException(25832): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
E/StorageException(25832): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
E/StorageException(25832): at java.lang.Thread.run(Thread.java:818)
E/StorageException(25832): Caused by: java.io.IOException: { "error": { "code": 403, "message": "Permission denied. Could not perform this operation" }}
E/StorageException(25832): at bha.a(:com.google.android.gms.dynamite_dynamitemodulesc#12685022#12.6.85 (040308-197041431):147)
E/StorageException(25832): at bha.a(:com.google.android.gms.dynamite_dynamitemodulesc#12685022#12.6.85 (040308-197041431):119)
E/StorageException(25832): at bgu.onTransact(:com.google.android.gms.dynamite_dynamitemodulesc#12685022#12.6.85 (040308-197041431):7)
E/StorageException(25832): at android.os.Binder.transact(Binder.java:387)
E/StorageException(25832): at com.google.android.gms.internal.firebase_storage.zza.transactAndReadExceptionReturnVoid(Unknown Source)
E/StorageException(25832): at com.google.android.gms.internal.firebase_storage.zzm.zzf(Unknown Source)
E/StorageException(25832): at com.google.android.gms.internal.firebase_storage.zzq.zza(Unknown Source)
E/StorageException(25832): at com.google.android.gms.internal.firebase_storage.zzf.zza(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.UploadTask.zzc(Unknown Source)
E/StorageException(25832): ... 6 more
E/StorageException(25832): StorageException has occurred.
E/StorageException(25832): User does not have permission to access this object.
E/StorageException(25832): Code: -13021 HttpResult: 403
E/StorageException(25832): The server has terminated the upload session
E/StorageException(25832): java.io.IOException: The server has terminated the upload session
E/StorageException(25832): at com.google.firebase.storage.UploadTask.zzs(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.UploadTask.zzr(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.UploadTask.run(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.StorageTask.zzl(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.zzq.run(Unknown Source)
E/StorageException(25832): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
E/StorageException(25832): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
E/StorageException(25832): at java.lang.Thread.run(Thread.java:818)
E/StorageException(25832): Caused by: java.io.IOException: { "error": { "code": 403, "message": "Permission denied. Could not perform this operation" }}
E/StorageException(25832): at bha.a(:com.google.android.gms.dynamite_dynamitemodulesc#12685022#12.6.85 (040308-197041431):147)
E/StorageException(25832): at bha.a(:com.google.android.gms.dynamite_dynamitemodulesc#12685022#12.6.85 (040308-197041431):119)
E/StorageException(25832): at bgu.onTransact(:com.google.android.gms.dynamite_dynamitemodulesc#12685022#12.6.85 (040308-197041431):7)
E/StorageException(25832): at android.os.Binder.transact(Binder.java:387)
E/StorageException(25832): at com.google.android.gms.internal.firebase_storage.zza.transactAndReadExceptionReturnVoid(Unknown Source)
E/StorageException(25832): at com.google.android.gms.internal.firebase_storage.zzm.zzf(Unknown Source)
E/StorageException(25832): at com.google.android.gms.internal.firebase_storage.zzq.zza(Unknown Source)
E/StorageException(25832): at com.google.android.gms.internal.firebase_storage.zzf.zza(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.UploadTask.zzc(Unknown Source)
E/StorageException(25832): ... 6 more
Is it possible to log in with an app account (service account?) so individual users do not need to log in?
What am I doing wrong here?

Quoting from your StorageException:
User does not have permission to access this object.
This is what you would expect because your rules state the following:
allow read, write: if request.auth != null;
Firebase uses authentication.
There are two options to solve this:
Either you authenticate your users with Firebase using the firebase_auth plugin
Or you make your files publicly available by changing your rules to allow read, write;
The Storage Rules documentation contains information about integrating Firebase Authentication.

Related

Error "No appropriate protocol" with MailR using gmail

I am trying to send a simple email from a gmail account using mailr:
send.mail(from = "XXXXXX#gmail.com",
to = c("YYYYYY#gmail.com"),
subject = "Subject of the email",
body = "test",
html = TRUE,
inline = TRUE,
smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "XXXXXX", passwd = "XXXXXX", ssl = TRUE),
authenticate = TRUE,
send = TRUE)
and it gives me the following error:
org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410)
at org.apache.commons.mail.Email.send(Email.java:1437)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at RJavaTools.invokeMethod(RJavaTools.java:386)
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
nested exception is:
javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2055)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697)
at javax.mail.Service.connect(Service.java:386)
at javax.mail.Service.connect(Service.jaNULL
va:245)
at javax.mail.Service.connect(Service.java:194)
at javax.mail.Transport.send0(Transport.java:253)
at javax.mail.Transport.send(Transport.java:124)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1400)
... 6 more
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
at sun.security.ssl.HandshakeContext.<init>(Unknown Source)
at sun.security.ssl.ClientHandshakeContext.<init>(Unknown Source)
at sun.security.ssl.TransportContext.kickstart(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:543)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:348)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:215)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2019)
... 13 more
Error: EmailException (Java): Sending the email to the following server failed : smtp.gmail.com:465
I just change the Unsafe application access to YES but nothing happens.

SafetyNet Attestation fails Flutter Firebase Phone Authentication

I am working on one of my flutter project and trying to add firebase phone authentication but I encountered with the error related to safetynet.Whereas i am able to use other authentication methods e.g. SignInWithEmailAndPassword. Whenever I am calling my phoneLogin function i am getting the error. I have already installed google play service on my emulator.
CODE
Future phoneLogin(String phone) async {
BuildContext context;
try {
await auth.verifyPhoneNumber(
phoneNumber: '+91$phone',
timeout: const Duration(seconds: 30),
verificationCompleted: (PhoneAuthCredential credentials) async {
await auth.signInWithCredential(credentials);
},
verificationFailed: (FirebaseAuthException exception) {},
codeSent: (String verificationId, [int forcedResendingToken]) {
// print('1')
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => OtpPage(phone: phone),
),
);
},
codeAutoRetrievalTimeout: (String abc) {});
return null;
} catch (e) {
return null;
}
}
ERROR
E/zzbf ( 6483): SafetyNet Attestation fails basic integrity.
I/zzkn ( 6483): Provider GmsCore_OpenSSL not available
W/System ( 6483): Ignoring header X-Firebase-Locale because its value was null.
D/AndroidRuntime( 6483): Shutting down VM
E/AndroidRuntime( 6483): FATAL EXCEPTION: main
E/AndroidRuntime( 6483): Process: com.oneobit.greenobit, PID: 6483
E/AndroidRuntime( 6483): java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/browser/customtabs/CustomTabsIntent$Builder;
E/AndroidRuntime( 6483): at com.google.firebase.auth.internal.RecaptchaActivity.zza(com.google.firebase:firebase-auth##20.0.2:13)
E/AndroidRuntime( 6483): at com.google.android.gms.internal.firebase-auth-api.zztw.zzb(com.google.firebase:firebase-auth##20.0.2:7)
E/AndroidRuntime( 6483): at com.google.android.gms.internal.firebase-auth-api.zztw.onPostExecute(Unknown Source:2)
E/AndroidRuntime( 6483): at android.os.AsyncTask.finish(AsyncTask.java:771)
E/AndroidRuntime( 6483): at android.os.AsyncTask.access$900(AsyncTask.java:199)
E/AndroidRuntime( 6483): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:788)
E/AndroidRuntime( 6483): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 6483): at android.os.Looper.loop(Looper.java:223)
E/AndroidRuntime( 6483): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/AndroidRuntime( 6483): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 6483): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/AndroidRuntime( 6483): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/AndroidRuntime( 6483): Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.browser.customtabs.CustomTabsIntent$Builder" on path: DexPathList[[zip file "/data/app/~~VMK8TkW9ozBJD9t7dnRn8g==/com.oneobit.greenobit-EtKxl5CBj6rDZiliq4I1ZQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~VMK8TkW9ozBJD9t7dnRn8g==/com.oneobit.greenobit-EtKxl5CBj6rDZiliq4I1ZQ==/lib/x86, /data/app/~~VMK8TkW9ozBJD9t7dnRn8g==/com.oneobit.greenobit-EtKxl5CBj6rDZiliq4I1ZQ==/base.apk!/lib/x86, /system/lib, /system_ext/lib]]
E/AndroidRuntime( 6483): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
E/AndroidRuntime( 6483): at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime( 6483): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime( 6483): ... 12 more
I/Process ( 6483): Sending signal. PID: 6483 SIG: 9
Lost connection to device.
I have already updated SHA256 key to my Firebase console.
Firebase have updated certain things one of them is they have included captcha verification before sending the code or OTP to mobile devices.
To solve this issue see bellow:
add the following to project/android/app/build.gradle
implementation "androidx.browser:browser:1.3.0"
add this in the dependencies section ...
dependencies {
implementation "androidx.browser:browser:1.3.0"
///
}
you can find the latest version here: android browser .
REASON:
The app tries to verify the captcha and send the code, for that it tries to launch a browser but because of the missing implementation it fails to load a browser and crashes the application.

IllegalArgumentException: Unsupported value: null while login with twitter

I am trying to login with Twitter when i used dependency firebase_auth:^0.6.6 it was working perfactly and i fetch the user's Profile picture and the Code was
final TwitterLoginResult result = await twitterLogin.authorize();
switch (result.status)
{
case TwitterLoginStatus.loggedIn:
var session = result.session;
FirebaseUser user = await _auth.signInWithTwitter(
authToken: session.token, authTokenSecret: session.secret);
img=user.photoUrl;
}
but i migrated the app to AndroidX and this dependency was not compatible so i used firebase_auth: ^0.14.0+5 and this code was not working so i change the code to
final TwitterLoginResult result = await twitterLogin.authorize();
switch (result.status) {
case TwitterLoginStatus.loggedIn:
var session = result.session;
final AuthCredential credential =
TwitterAuthProvider.getCredential(authToken: session.token,
authTokenSecret: session.secret);
FirebaseUser user = (await _auth.signInWithCredential(credential)).user;
and this code is not working app is Crashing and showing the error
W/BiChannelGoogleApi(18829): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzak#70a4ccf
W/InputMethodManager(18829): startInputReason = 1
D/FirebaseAuth(18829): Notifying id token listeners about user ( D71yiiEX7ubSon4xxcddKlSydn72 ).
D/FirebaseAuth(18829): Notifying auth state listeners about user ( D71yiiEXccccccccKlSydn72 ).
I/zygote64(18829): Do full code cache collection, code=124KB, data=91KB
I/zygote64(18829): After code cache collection, code=123KB, data=68KB
I/zygote64(18829): Do partial code cache collection, code=123KB, data=68KB
I/zygote64(18829): After code cache collection, code=123KB, data=68KB
I/zygote64(18829): Increasing code cache capacity to 512KB
D/AndroidRuntime(18829): Shutting down VM
E/AndroidRuntime(18829): FATAL EXCEPTION: main
E/AndroidRuntime(18829): Process: com.example.login_app, PID: 18829
E/AndroidRuntime(18829): java.lang.IllegalArgumentException: Unsupported value: null
E/AndroidRuntime(18829): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:294)
E/AndroidRuntime(18829): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:291)
E/AndroidRuntime(18829): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:291)
E/AndroidRuntime(18829): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:291)
E/AndroidRuntime(18829): at io.flutter.plugin.common.StandardMethodCodec.encodeSuccessEnvelope(StandardMethodCodec.java:57)
E/AndroidRuntime(18829): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:225)
E/AndroidRuntime(18829): at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin$SignInCompleteListener.onComplete(FirebaseAuthPlugin.java:691)
E/AndroidRuntime(18829): at com.google.android.gms.tasks.zzj.run(Unknown Source:4)
E/AndroidRuntime(18829): at android.os.Handler.handleCallback(Handler.java:808)
E/AndroidRuntime(18829): at android.os.Handler.dispatchMessage(Handler.java:101)
E/AndroidRuntime(18829): at android.os.Looper.loop(Looper.java:166)
E/AndroidRuntime(18829): at android.app.ActivityThread.main(ActivityThread.java:7529)
E/AndroidRuntime(18829): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(18829): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
E/AndroidRuntime(18829): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
I/Process (18829): Sending signal. PID: 18829 SIG: 9
Lost connection to device.
Please can someone explain to me how to resolve this problem?
Problem is with login task AND Androidx twitter_login_issue
Add this dependency in your pubspec.yaml file and let me know this working or not?
flutter_twitter_login:
git: git://github.com/eudangeld/flutter_twitter_login.git
Same issue (question) login_issue

Flutter app crashes on concurrent transactions performed on cloud Firestore

I am trying to develop an app where multiple users log in and completes a poll concurrently.
In this, as soon as user submits the answer the transaction is ran to increment the counter for given answer
try {
DocumentSnapshot freshsnap = await tx.get(reff);
try {
await tx.update(reff, <String, dynamic>{
'$i': freshsnap['$i'] + 1,
});
} catch (error) {
print("Error" + error.code);
}
} catch (error) {
if (error is PlatformException &&
error.code == 'Error performing transaction') {
// await tx.set(ref, data);
print("Error" + error.code);
} else
rethrow;
}
}).catchError((onError){
print("Error on: "+onError);
});
as soon as the multiple users submit the same answer for same question concurrently i.e The same field in same document is requested to update by multiple users concurrently the app crashes and generates following error:
FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime(12169): Process: com.rrcg.tumerboared, PID: 12169
E/AndroidRuntime(12169): java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime(12169): at android.os.AsyncTask$3.done(AsyncTask.java:354)
E/AndroidRuntime(12169): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
E/AndroidRuntime(12169): at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
E/AndroidRuntime(12169): at java.util.concurrent.FutureTask.run(FutureTask.java:271)
E/AndroidRuntime(12169): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
E/AndroidRuntime(12169): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime(12169): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime(12169): at java.lang.Thread.run(Thread.java:764)
E/AndroidRuntime(12169): Caused by: java.lang.AssertionError: INTERNAL ASSERTION FAILED: A transaction object cannot be used after its update callback has been invoked.
E/AndroidRuntime(12169): at com.google.firebase.firestore.util.Assert.fail(com.google.firebase:firebase-firestore##21.2.1:46)
E/AndroidRuntime(12169): at com.google.firebase.firestore.util.Assert.hardAssert(com.google.firebase:firebase-firestore##21.2.1:31)
E/AndroidRuntime(12169): at com.google.firebase.firestore.core.Transaction.ensureCommitNotCalled(com.google.firebase:firebase-firestore##21.2.1:246)
E/AndroidRuntime(12169): at com.google.firebase.firestore.core.Transaction.lookup(com.google.firebase:firebase-firestore##21.2.1:81)
E/AndroidRuntime(12169): at com.google.firebase.firestore.Transaction.getAsync(com.google.firebase:firebase-firestore##21.2.1:191)
E/AndroidRuntime(12169): at com.google.firebase.firestore.Transaction.get(com.google.firebase:firebase-firestore##21.2.1:228)
E/AndroidRuntime(12169): at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$5.doInBackground(CloudFirestorePlugin.java:550)
E/AndroidRuntime(12169): at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$5.doInBackground(CloudFirestorePlugin.java:545)
E/AndroidRuntime(12169): at android.os.AsyncTask$2.call(AsyncTask.java:333)
E/AndroidRuntime(12169): at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/AndroidRuntime(12169): ... 4 more
Have no idea why is this happening, since transaction should allow multiple users to update a field of a document concurrently.
If you are running on a physical iOS device, the crash is caused by this bug in the FlutterFire binding library. There doesn't seem to be a workaround, so keep an eye on the issue for updates.
I solved this by making the transaction object (tx) non-async and moving the async logic outside the transaction block. After all, the whole point of transactions is to execute its instructions atomically and async instructions kind of defeat this purpose.

Access to Firebase Storage in Flutter

I'm fairly new to Flutter and haven't ever used Firebase before so my aplogies if there is an obvious solution to this.
I'm working on a Flutter app which involves recording form submissions and submitting them to a central location.
Firebase Storage seemed like a good fit since as I understood it the app can upload files to the cloud bucket and then they can be accessed through the Firebase console. Correct me if I'm wrong.
So I found this module for Flutter;
https://pub.dartlang.org/packages/firebase_storage
I used the example code as a basis.
once at the start of the code I call;
final FirebaseApp app = await FirebaseApp.configure(
name: 'test',
options: new FirebaseOptions(
googleAppID: Platform.isIOS
? '{ios app id}'
: '{android app ID}',
gcmSenderID: '{project number code}',
apiKey: '{web api key from the firebase console}',
projectID: '{project ID}',
),
);
storage = new FirebaseStorage(
app: app, storageBucket: '{address to data bucket}');
Then to upload a file I've tried;
final StorageReference ref =
storage.ref().child('uploads').child(filename);
final StorageUploadTask uploadTask = ref.putFile(
file,
new StorageMetadata(
contentLanguage: 'en',
customMetadata: <String, String>{'activity': 'submission'},
),
);
final Uri downloadUrl = (await uploadTask.future).downloadUrl;
final http.Response downloadData = await http.get(downloadUrl);
final String name = await ref.getName();
final String bucket = await ref.getBucket();
final String path = await ref.getPath();
return downloadData.statusCode >= 200 && 299 >= downloadData.statusCode;
and in the Firebase console I created the Uploads folder and I think set everything else up correctly.
My Firebase storage access rules look like this;
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
My issue is that when I try to upload the file I get the following error;
W/DynamiteModule(25832): Local module descriptor class for com.google.android.gms.firebasestorage not found.
I/DynamiteModule(25832): Considering local module com.google.android.gms.firebasestorage:0 and remote module com.google.android.gms.firebasestorage:6
I/DynamiteModule(25832): Selected remote version of com.google.android.gms.firebasestorage, version >= 6
W/System (25832): ClassLoader referenced unknown path: /data/data/com.google.android.gms/app_chimera/m/00000040/n/armeabi-v7a
W/System (25832): ClassLoader referenced unknown path: /data/data/com.google.android.gms/app_chimera/m/00000040/n/armeabi
E/StorageUtil(25832): error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.
W/NetworkRequest(25832): no auth token for request
E/StorageException(25832): StorageException has occurred.
E/StorageException(25832): User does not have permission to access this object.
E/StorageException(25832): Code: -13021 HttpResult: 403
E/StorageException(25832): The server has terminated the upload session
E/StorageException(25832): java.io.IOException: The server has terminated the upload session
E/StorageException(25832): at com.google.firebase.storage.UploadTask.zzs(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.UploadTask.zzr(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.UploadTask.run(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.StorageTask.zzl(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.zzq.run(Unknown Source)
E/StorageException(25832): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
E/StorageException(25832): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
E/StorageException(25832): at java.lang.Thread.run(Thread.java:818)
E/StorageException(25832): Caused by: java.io.IOException: { "error": { "code": 403, "message": "Permission denied. Could not perform this operation" }}
E/StorageException(25832): at bha.a(:com.google.android.gms.dynamite_dynamitemodulesc#12685022#12.6.85 (040308-197041431):147)
E/StorageException(25832): at bha.a(:com.google.android.gms.dynamite_dynamitemodulesc#12685022#12.6.85 (040308-197041431):119)
E/StorageException(25832): at bgu.onTransact(:com.google.android.gms.dynamite_dynamitemodulesc#12685022#12.6.85 (040308-197041431):7)
E/StorageException(25832): at android.os.Binder.transact(Binder.java:387)
E/StorageException(25832): at com.google.android.gms.internal.firebase_storage.zza.transactAndReadExceptionReturnVoid(Unknown Source)
E/StorageException(25832): at com.google.android.gms.internal.firebase_storage.zzm.zzf(Unknown Source)
E/StorageException(25832): at com.google.android.gms.internal.firebase_storage.zzq.zza(Unknown Source)
E/StorageException(25832): at com.google.android.gms.internal.firebase_storage.zzf.zza(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.UploadTask.zzc(Unknown Source)
E/StorageException(25832): ... 6 more
E/StorageException(25832): StorageException has occurred.
E/StorageException(25832): User does not have permission to access this object.
E/StorageException(25832): Code: -13021 HttpResult: 403
E/StorageException(25832): The server has terminated the upload session
E/StorageException(25832): java.io.IOException: The server has terminated the upload session
E/StorageException(25832): at com.google.firebase.storage.UploadTask.zzs(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.UploadTask.zzr(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.UploadTask.run(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.StorageTask.zzl(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.zzq.run(Unknown Source)
E/StorageException(25832): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
E/StorageException(25832): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
E/StorageException(25832): at java.lang.Thread.run(Thread.java:818)
E/StorageException(25832): Caused by: java.io.IOException: { "error": { "code": 403, "message": "Permission denied. Could not perform this operation" }}
E/StorageException(25832): at bha.a(:com.google.android.gms.dynamite_dynamitemodulesc#12685022#12.6.85 (040308-197041431):147)
E/StorageException(25832): at bha.a(:com.google.android.gms.dynamite_dynamitemodulesc#12685022#12.6.85 (040308-197041431):119)
E/StorageException(25832): at bgu.onTransact(:com.google.android.gms.dynamite_dynamitemodulesc#12685022#12.6.85 (040308-197041431):7)
E/StorageException(25832): at android.os.Binder.transact(Binder.java:387)
E/StorageException(25832): at com.google.android.gms.internal.firebase_storage.zza.transactAndReadExceptionReturnVoid(Unknown Source)
E/StorageException(25832): at com.google.android.gms.internal.firebase_storage.zzm.zzf(Unknown Source)
E/StorageException(25832): at com.google.android.gms.internal.firebase_storage.zzq.zza(Unknown Source)
E/StorageException(25832): at com.google.android.gms.internal.firebase_storage.zzf.zza(Unknown Source)
E/StorageException(25832): at com.google.firebase.storage.UploadTask.zzc(Unknown Source)
E/StorageException(25832): ... 6 more
Is it possible to log in with an app account (service account?) so individual users do not need to log in?
What am I doing wrong here?
Quoting from your StorageException:
User does not have permission to access this object.
This is what you would expect because your rules state the following:
allow read, write: if request.auth != null;
Firebase uses authentication.
There are two options to solve this:
Either you authenticate your users with Firebase using the firebase_auth plugin
Or you make your files publicly available by changing your rules to allow read, write;
The Storage Rules documentation contains information about integrating Firebase Authentication.

Resources