8

Firebase Storage show "error loading preview" in the firebase console

Initially during uploading and loading it worked fine in my app. After Two days when I am checking if my app is working fine or not.

Screenshot of the firebase console:

enter image description here

My image uploading code:

if(imagePath!=null) {                                  
   FirebaseStorage.getInstance().getReference("admin").child(admin.getId()).putFile(imagePath);
}

My image Loading code:

FirebaseStorage.getInstance().getReference("admin").child(image_path) .getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
            @Override
            public void onSuccess(Uri uri) {
                Glide.with(getApplicationContext()).load(uri).centerCrop().into(profileImage);
            }
        });

Please help me how to overcome this problem if you know. Thanks Advance to firebase expertists

Community
  • 1
  • 1
Md Mahmudul Islam
  • 2,514
  • 4
  • 18
  • 33

3 Answers3

2

I just emailed Firebase Team about this issue today.

They just replied my email just half an hour ago.

My Email

Firebase Storage Error Loading Preview firebase team email

Firebase Team Reply

Firebase Storage Error Loading Preview firebase team email reply

Edit: Use VPN to solve this problem.

Shariful Islam Mubin
  • 2,146
  • 14
  • 23
1

You said,your project was working two days ago.Your image uploaded as I can see but isn't loading. That means there is nothing wrong with the code. May be firebase has updated it's version,that's why it created bug.You might follow the updated documentation. In my previous iOS project, I faced same type of error for firebase default authUI, as firebase had some type of update, so they changed some instructions in their updated documentation. I also request to update android studio and its plugins,migrating to androidX if you haven't.You have change xml design code (like dependency reference etc)after migration else it will crash the app

Here is the sample java code from firebase documentation for Android to upload files

Must create a reference

// Create a storage reference from our app
StorageReference storageRef = storage.getReference();

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

// Create a reference to 'images/mountains.jpg'
StorageReference mountainImagesRef = storageRef.child("images/mountains.jpg");

// While the file names are the same, the references point to different files
mountainsRef.getName().equals(mountainImagesRef.getName());    // true
mountainsRef.getPath().equals(mountainImagesRef.getPath());    // false

then upload image from local storage

Uri file = Uri.fromFile(new File("path/to/images/rivers.jpg"));
StorageReference riversRef = storageRef.child("images/"+file.getLastPathSegment());
uploadTask = riversRef.putFile(file);

// Register observers to listen for when the download is done or if it fails
uploadTask.addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception exception) {
        // Handle unsuccessful uploads
    }
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
    @Override
    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
        // taskSnapshot.getMetadata() contains file metadata such as size, content-type, etc.
        // ...
    }
});

For downloading image

Create Reference

// Create a storage reference from our app
StorageReference storageRef = storage.getReference();

// Create a reference with an initial file path and name
StorageReference pathReference = storageRef.child("images/stars.jpg");

// Create a reference to a file from a Google Cloud Storage URI
StorageReference gsReference = storage.getReferenceFromUrl("gs://bucket/images/stars.jpg");

// Create a reference from an HTTPS URL
// Note that in the URL, characters are URL escaped!
StorageReference httpsReference = storage.getReferenceFromUrl("https://firebasestorage.googleapis.com/b/bucket/o/images%20stars.jpg");

Download Image to local file

islandRef = storageRef.child("images/island.jpg");

File localFile = File.createTempFile("images", "jpg");

islandRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
    @Override
    public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
        // Local temp file has been created
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception exception) {
        // Handle any errors
    }
});

More Details https://firebase.google.com/docs/storage/android/upload-files https://firebase.google.com/docs/storage/android/download-files

  • 2
    I am trying but still not working and it isn't execute any success or failure function – Md Mahmudul Islam Dec 30 '19 at 15:51
  • It's ok, it might be the problem with google storage server. https://firebase.google.com/support/troubleshooter/contact . Contact them directly if possible. Please be specific while sending them message.choose the email subject as Bug report. – samir imtiaz Dec 30 '19 at 16:42
  • Guys, I am facing the same issue. The fully working project has parsed all information except image. And it was working perfectly two days ago. Now images not even showing on storage console. Always getting `Error loading preview`. Please help! – Tulon Jan 01 '20 at 20:53
1

This is Mubin from Bangladesh

Our app called "Ostad" is up and running in Google Play Store since 4 months. And, our user profile images are hosted in Firebase Storage. Suddenly user images are not loading in the app from today. After checking all the things in the Firebase & Google Cloud Platform (GCP), I realised that maybe it was an issue with the Google Cloud servers in the Mumbai Region. And, we wait if it fixes automatically.

And our guess was correct. Just around 20 minutes before, images are loading now.
Now, all are ok.

I think, you're also facing trouble with the same issue.

Just wait to see if it works again later.

Edit: Use VPN to solve this problem.

Shariful Islam Mubin
  • 2,146
  • 14
  • 23
  • I hope it will work because you told images were loading yesterday. That means your code is alright. Just wait now till google fixes their storage servers. – Shariful Islam Mubin Dec 30 '19 at 16:16
  • 1
    still not working for the app I am developing now. but works for existing app perfectly. I don't know why. – Md Mahmudul Islam Jan 02 '20 at 19:18
  • 2 more developer just contacted with personally about this issue. They're also facing same issues from some days. They're also select their firebase server in Mumbai region. We also faced this issue again. Sometime it works and, most of the time storage server is getting down. We all can do now is that, we can email firebase support team about this issue with our server region. – Shariful Islam Mubin Jan 03 '20 at 07:39
  • Firebase support contact: https://firebase.google.com/support/troubleshooter/contact – Shariful Islam Mubin Jan 03 '20 at 07:48