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

19

13

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.

Gpo answered 29/12, 2017 at 15:42 Comment(0)
H
11

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.

Hart answered 10/6, 2019 at 14:42 Comment(2)
May God bless youTubman
how can I do it ?Faithfaithful
S
6

update your firebase-storage dependency

implementation 'com.google.firebase:firebase-storage:17.0.0'
Sideline answered 13/6, 2019 at 19:37 Comment(0)
O
4

This error is generated because of rules defined under rules tab in storage, by deafult the rules will be - rules_version = '2'; service firebase.storage { match /b/{bucket}/o { match /{allPaths=**} { allow read, write if request.auth != null; } } }

if u have not implmented authentication and ttying to store files in storage then implment authentication or just remove it if you are implementing for learning purpose, dont use this in production application.

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

Oceanus answered 13/9, 2021 at 6:50 Comment(1)
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 falseMorrell
M
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.

Moscow answered 29/12, 2017 at 17:18 Comment(1)
thank you. Will I save to the drawble of the application?Gpo
M
3

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

Mcneal answered 16/2, 2020 at 20:9 Comment(0)
C
2

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);
Corps answered 7/8, 2020 at 7:57 Comment(0)
I
1

In my case I had to paste the rule below and publish on my storage.

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if true;
    }
  }
}
Inositol answered 6/3, 2019 at 7:48 Comment(0)
T
1

The key to solving this problem is to enable Storage in the app's permissions. You should follow these steps:

Settings -> Apps -> AppName -> Permissions -> Enable Storage

Remember that the file should exist on the device.

Talesman answered 28/11, 2019 at 16:31 Comment(0)
J
1

Make sure you've connected to firebase. Open the firebase assistant, go to storage, click on upload and download a file from storage and check. Connecting is easy. Just click on the connect button.

Jumbuck answered 14/12, 2019 at 15:29 Comment(0)
B
1

Add correct dependencies:

implementation 'com.google.firebase:firebase-auth:17.0.0'
implementation 'com.google.firebase:firebase-storage:17.0.0'
implementation 'com.google.firebase:firebase-database:17.0.0'
Bellinger answered 15/3, 2020 at 11:0 Comment(0)
T
1

In my case, I have exceeded the downloading Quota which is of 1GB/day. When I tried next day I could able to download without any issue.

Tanatanach answered 1/5, 2022 at 9:47 Comment(0)
T
0

May be this is the wrong path bug but in my case resolve this here is the example

i use this code then i received error

public static StorageReference getChildProfileStorage(String vid){
    StorageReference storageReference= FirebaseStorage.getInstance().getReference();
    storageReference.child("ParentDataStore").child(CurrentUser.getInstance().getEmail())
            .child("ChildDataStore").child(vid);

    return storageReference;
}

here is the line that solve my problem

public static StorageReference getStudentProfileStorage(String vid){
    StorageReference storageReference= FirebaseStorage.getInstance().getReference("ParentDataStore")
            .child("StudentDataStore").child(vid).child("profile");
    return storageReference;
}
Tic answered 1/7, 2020 at 13:53 Comment(0)
G
0

For me this error was triggered when uploading a 0.0 KB image file; that is because I was testing image compression algorithm that has a bug resulting in 0.0 KB image in some cases.

So, make sure that the image/file you upload is greater than 0 KB.

Gamin answered 22/10, 2020 at 4:0 Comment(0)
A
0

For me adding android:requestLegacyExternalStorage="true" in the application tag in the menifest file solved the error. But there can be various reasons for this error, since it is not pointing out the reason. But things can be done. First update the storage library of firebase to latest version in gradle file. Second check permissions in android settings

Amphictyon answered 8/11, 2020 at 10:51 Comment(0)
H
0

For me it working properly if the upload file is no symbols such +, @, #, $ make sure the file name is only number, letters, period, and underscore.

Hertfordshire answered 14/1, 2021 at 8:28 Comment(0)
G
0

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

I got this again when I tried to download a file from Firebase Storage using .getFile() method, and the reason is that I didn't grant the app WRITE_EXTERNAL_STORAGE permission before doing that.

File dir = new File(Environment.getExternalStorageDirectory(), "subDir");
File file = new File(dir, "fileName");

firebaseStorage.getReference().child("someDirectory").child("fileName").getFile(file);
Gamin answered 27/3, 2021 at 23:51 Comment(0)
G
0

I had something similar (not same ) and eventually enabling the write external permission fixed my problem. pay attention - it needs special permission ( to ask from the user , and not only installation permission -began in android 6) .

Gerdy answered 11/8, 2021 at 2:35 Comment(0)
G
0

Update BOM; fixed mine problem with this. learn latest version of bom : https://firebase.google.com/docs/android/setup

dependencies {

    .....
    implementation platform('com.google.firebase:firebase-bom:30.1.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-storage'
    implementation 'com.google.firebase:firebase-firestore'
} 
Gravelly answered 30/5, 2022 at 6:5 Comment(0)
N
0

In my case it was that i have to change rules version to version 2, i put this on top of storage rules:

rules_version = "2";
Nucleotidase answered 18/4, 2023 at 21:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.