StorageException: An unknown error occurred, please check the HTTP result code and inner exception for server response

19,100

Solution 1

This Sorted me out, All I needed to do was to update the firebase-storage lib. In my case it was 'com.google.firebase:firebase-storage:16.4.0' and after updating it to 'com.google.firebase:firebase-storage:17.0.0' everything start working fine again.

Solution 2

update your firebase-storage dependency

implementation 'com.google.firebase:firebase-storage:17.0.0'

Solution 3

You can't use putFile() with an HTTP type Uri. According to the documentation, you're supposed to use it to upload a local file.

If you want to upload a file to Storage that exists somewhere else referenced by an HTTP URL, you'll have to download that file first, store it locally, then upload it.

Solution 4

So the I had the same problem and I easily fixed it!, so this is not a problem with firebase, but the problem is that your file can not be accessed from your local disk!

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

for api 21+ you will need to request permission, for security reasons, check this article for more information: How to request storage permission

Solution 5

Using putStream() is the the recommended way for most files instead of putFile() (for local files on the device) like so:

InputStream stream = new FileInputStream(new File(pathToYourFile)));

UploadTask uploadTask = imageFileStorageReference.putStream(stream);
Share:
19,100
FPoly HCM - K123v2 Le Xuan Du
Author by

FPoly HCM - K123v2 Le Xuan Du

Updated on June 12, 2022

Comments

  • FPoly HCM - K123v2 Le Xuan Du
    FPoly HCM - K123v2 Le Xuan Du about 2 years

    I use Firebase Storage to upfile. But it does not work THIS IS MY CODE.

    FirebaseStorage storage = FirebaseStorage.getInstance();
    StorageReference storageRef = storage.getReferenceFromUrl("gs://the-food-house.appspot.com/");
    // Create a reference to "file"
        StorageReference mStorage = storageRef.child("Album Avatar")
                .child(UserUID)
                .child(AvatarUser.getLastPathSegment());
        mStorage.putFile(AvatarUser).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                Toast.makeText(SignUpWithEmail.this, "UPLOAD FILE OK", Toast.LENGTH_SHORT).show();
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Log.d("ERROR", e.toString());
                Toast.makeText(SignUpWithEmail.this, "Failed", Toast.LENGTH_SHORT).show();
            }
        };
    

    Here is the error I am having:

    com.google.firebase.storage.StorageException: An unknown error occurred, please check the HTTP result code and inner exception for server response.
    

    And this is details of error:

    Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 
    E/UploadTask: could not locate file for uploading:https://firebasestorage.googleapis.com/v0/b/the-food-house.appspot.com/o/Avatar%20Default%2Fmale.png?alt=media&token=3f285cab-c32b-4f33-a909-5a85ef62d74d
    E/StorageException: StorageException has occurred.
    An unknown error occurred, please check the HTTP result code and inner exception for server response.
        Code: -13000 HttpResult: 0 
    E/StorageException: No content provider: https://firebasestorage.googleapis.com/v0/b/the-food-house.appspot.com/o/Avatar%20Default%2Fmale.png?alt=media&token=3f285cab-c32b-4f33-a909-5a85ef62d74d
    java.io.FileNotFoundException: No content provider: https://firebasestorage.googleapis.com/v0/b/the-food-house.appspot.com/o/Avatar%20Default%2Fmale.png?alt=media&token=3f285cab-c32b-4f33-a909-5a85ef62d74d
        at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1131)
        at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:982)
        at android.content.ContentResolver.openInputStream(ContentResolver.java:702)
        at com.google.firebase.storage.UploadTask.<init>(Unknown Source)
        at com.google.firebase.storage.StorageReference.putFile(Unknown Source)
        at thedark.example.com.thefoodhouse.Activity.Authencation.SignUpWithEmail.submitAvatarStorage(SignUpWithEmail.java:111)
        at thedark.example.com.thefoodhouse.Activity.Authencation.SignUpWithEmail.access$1200(SignUpWithEmail.java:38)
        at thedark.example.com.thefoodhouse.Activity.Authencation.SignUpWithEmail$5.onComplete(SignUpWithEmail.java:170)
        at com.google.android.gms.tasks.zzf.run(Unknown Source)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6077)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
    

    This is rule firebase:

    allow read, write: if request.auth != null;
    

    It has given me a headache these past few days. Hope that someone finds the problem. Help me please. Thank you.

  • FPoly HCM - K123v2 Le Xuan Du
    FPoly HCM - K123v2 Le Xuan Du over 6 years
    thank you. Will I save to the drawble of the application?
  • Filip Markoski
    Filip Markoski about 5 years
    May God bless you
  • ahmed
    ahmed over 2 years
    Thanks, mine default rule for write was "write if false" on a new project, it should've been "write if request.auth != null" so only authenticated users can write. I spent hours trying to debug as previously on new projects, the default was always "write if request.auth != null; ", now it seems default is false