'StorageException: An unknown error occurred, please check the HTTP result code and inner exception for server response
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.
Solution 1:[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:[2]
update your firebase-storage dependency
implementation 'com.google.firebase:firebase-storage:17.0.0'
Solution 3:[3]
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;
}
}
}
Solution 4:[4]
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 5:[5]
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 6:[6]
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);
Solution 7:[7]
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;
}
}
}
Solution 8:[8]
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.
Solution 9:[9]
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.
Solution 10:[10]
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'
Solution 11:[11]
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.
Solution 12:[12]
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;
}
Solution 13:[13]
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.
Solution 14:[14]
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.
Solution 15:[15]
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);
Solution 16:[16]
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
Solution 17:[17]
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) .
Solution 18:[18]
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'
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow