Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Storage is giving StorageException while trying to upload images

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)

like image 892
Pratima Avatar asked May 31 '16 10:05

Pratima


People also ask

How to upload file Firebase Storage?

To upload a file to Cloud Storage, you first create a reference to the full path of the file, including the file name. Once you've created an appropriate reference, you then call the putBytes() , putFile() , or putStream() method to upload the file to Cloud Storage.


2 Answers

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

like image 124
Siv Avatar answered Oct 20 '22 23:10

Siv


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.

like image 24
Val Avatar answered Oct 20 '22 21:10

Val