0
votes

I am building an android app which allows users to upload pictures to firebase storage. I am still in development mode so I set up my storage rules to public. When the user selects a picture to upload, the file is not uploaded but the download URL is returned. Logcat shows the following error

E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.

And here is my storage rules

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

And my android java code:

private void uploadPic() {
StorageReference mStorageRef = FirebaseStorage.getInstance().getReference();
        Uri fileUrl = Uri.fromFile(new File(filePath));
        String fileExt = MimeTypeMap.getFileExtensionFromUrl(fileUrl.toString());
        final String fileName = UUID.randomUUID().toString()+"."+fileExt;
        StorageReference profilePicsRef = mStorageRef.child("profile_pics/"+fileName);
        profilePicsRef.putFile(fileUrl)
                .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                        // Get a URL to the uploaded content
                        Uri downloadUrl = taskSnapshot.getDownloadUrl();
                      Log.d("DOWNLOAD_URL", downloadUrl.toString());

                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception exception) {
                        // Handle unsuccessful uploads
                        // ...
                        Toast.makeText(getApplicationContext(), "Error: "+exception.toString(), Toast.LENGTH_LONG).show();

                    }
                });
}

Any help will be greatly appreciated.

UPDATE

I have narrowed down the problem: I have two folders in storage, I can upload to the "Videos" folder, but not to the "profile_pics" folder or any other folder. Why is this happening?

1
Have you got google-services.json in AppName/App folder? Did u use the firebase Android Studio assistant?Tatsuya
Yes I have google-services.json in app folder and have setup firebase using "assistant". I also use firestore which works without any issue, its the storage am having issues with.Acheme Paul
I can post some code of a firestore app that I did yesterday if f you want to try the code.Tatsuya
Like I said firestore works just fine. Am having trouble uploading to firebase storageAcheme Paul

1 Answers

6
votes

For some reason unknown to mere mortals, the gods have refused upload to any folder that starts with "profile". I had to create another folder "users_profile_pic". Three days wasted!