6
votes

I have been trying to upload images to the new firebase storage service . It is throwing StorageException

E/StorageException: StorageException has occurred. An unknown error occurred, please check the HTTP result code and inner exception for server response. Code: -13000 HttpResult: 400

E/StorageException: The server has terminated the upload session java.io.IOException: The server has terminated the upload session at com.google.firebase.storage.UploadTask.zzVi(Unknown Source) at com.google.firebase.storage.UploadTask.zzVh(Unknown Source) at com.google.firebase.storage.UploadTask.run(Unknown Source) at com.google.firebase.storage.StorageTask$5.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)

15
Did you find a solution for it? I too get this error but on very few phones.Parag Kadam

15 Answers

5
votes

In the google firebase this type of StorageException are commonly caused because of wrong StorageReference reference .

FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReferenceFromUrl("gs://<your-bucket-name>");

// Create a reference to "file"
StorageReference mountainsRef = storageRef.child("file.jpg");

Make sure the reference to the file is made correctly.


Documentation Refrences

Details about creating Storage reference can be found in here

Details about the Storage Exception codes can be found in here for further refrences

4
votes

I was also getting the same exception but got over with it by simply granting Storage Permission to app from:

Settings > Apps > {My App} > Permissions > Enable Storage

The above part can also be done through Java code, I learned it in a tutorial for Android Marshmallow. Also, make sure to declare permission for INTERNET and READ_EXTERNAL_STORAGE in Android Manifest file. However, if you are still getting the exception, try updating play services as well.

4
votes

In your firebase console, go to the storage tab on the left. Click on the rules tab and set your rule to public. Use the following code to set it to public.

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

This is good for testing purpose, however, you should secure your DB connection using authenticate users.

4
votes

This Sorted me out, not a single line of code change ;) , 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.

2
votes

Don't forget to add

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

In your AndroidManifest.xml

1
votes

I encountered the same issue today.

1
votes

Enable anonymous authentication in firebase console.

1
votes

I was facing the same issue. I removed existed google.services.json file, download once again from firebase console and add it to my project.Now it is working successfully.

0
votes

I had encountered this issue, when I had not created the referenced folder/bucket in the Firebase Storage. Unlike Firebase Database, I think (I am not sure yet), the Storage reference will not create the bucket if it doesn't exist in the first place. So, create a folder first, and then try again.

0
votes
  1. Start with checking if you have granted the Permission of Internet in Your Manifest.

  2. Check if You have Granted The Correct Authorization Permission To Write To Your Storage in The "Rules" tab of your Storage.

  3. Try Logging the reference to Your Firebase Storage as well as to the File You are trying to upload. Check if its the same as the Firebase Project You are Working On In The Browser.

In my case the project configuration was wrong, which is pretty much the first thing we do in the project. But hey! Its better than missing out on a ";"

0
votes

I was also facing the same,

  1. Update all the suggested dependencies from project structure
  2. Update Google play services
0
votes
```private StorageReference mStorage;
final StorageReference filepath = mStorage.child("log_images");
Task<Uri> downloadurl = filepath.getDownloadUrl();```

check the above and last make sure the yourlatest for latest version google search (android and firebase) 'com.google.firebase:firebase-storage:19.1.1'

0
votes

I was having the same issue. It's not storage permission problem, i just changed the Firebase Storage Rules then solved.

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

Above are default rules which works fine. Changing the condition may cause Exception. Please check your condition before use.

0
votes

This problem may cause of authentication while uploading in firestore . You have to remove authentication part in the code of the rules of firebase storage.

Remove this and publish :if request.auth != null;

0
votes

No matter what the storage reference is.. You need to put a proper URI of the file to upload in putFile() method.