Skip to content Skip to sidebar Skip to footer

Firebase Storage "retrieves A Long Lived Download Url" Using Getdownloadurl() Now Deprecated

This getDownloadUrl() method showed deprecated after updating to 'com.google.firebase:firebase-storage:15.0.2' Nothing on the official site to another way to achieve the url

Solution 1:

In the docs it says this:

The getDownloadUrl() and getDownloadUrls() methods of the StorageMetadata class are now deprecated. Use getDownloadUrl() from StorageReference instead.

So you need to use getDownloadUrl() that is inside the StorageReference

public Task<Uri> getDownloadUrl ()

Asynchronously retrieves a long lived download URL with a revokable token. This can be used to share the file with others, but can be revoked by a developer in the Firebase Console if desired.

more information here:

https://firebase.google.com/docs/reference/android/com/google/firebase/storage/StorageReference#getDownloadUrl()

Solution 2:

finalStorageReferencefilePath= mImageStore.child("profile_images").child("full_image").child(userId + ".jpg");
                filePath.getDownloadUrl().addOnSuccessListener(newOnSuccessListener<Uri>() {
                    @OverridepublicvoidonSuccess(Uri uri) {
                        //Bitmap hochladen
                        uploadBitMap(uri.toString());
                    }
                });strong text

Or

finalUploadTaskuploadTask= thumb_file.putBytes(thumb_bite);
        uploadTask.addOnSuccessListener(newOnSuccessListener<UploadTask.TaskSnapshot>() {
            @OverridepublicvoidonSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                //Url laden
                taskSnapshot.getStorage().getDownloadUrl().addOnSuccessListener(newOnSuccessListener<Uri>() {
                    @OverridepublicvoidonSuccess(Uri uri) {
                        MapimageUrls=newHashMap();
                        imageUrls.put("image", fullImageUrl);
                        imageUrls.put("thumb_image", uri.toString());
                        //In database
                        mAlarmsDatabaseReference.updateChildren(imageUrls).addOnCompleteListener(newOnCompleteListener<Void>() {
                            @OverridepublicvoidonComplete(@NonNull Task<Void> task) {
                                //Progressbar beende + Bild wieder anzeigen
                                progressBar.setVisibility(View.GONE);
                                circleProfilePicture.setVisibility(View.VISIBLE);

                                if(task.isSuccessful()){
                                    Toast.makeText(SettingsActivity.this, getResources().getString(R.string.ProfilbildUpdate), Toast.LENGTH_SHORT).show();
                                }else{
                                    Toast.makeText(SettingsActivity.this, "FAILED", Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
                    }
                });
            }
        });

Solution 3:

final UploadTask uploadTask = thumb_file.putBytes(thumb_bite); uploadTask.addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

//Url laden
            taskSnapshot.getStorage().getDownloadUrl().addOnSuccessListener(newOnSuccessListener<Uri>() {
                @OverridepublicvoidonSuccess(Uri uri) {
                    MapimageUrls=newHashMap();
                    imageUrls.put("image", fullImageUrl);
                    imageUrls.put("thumb_image", uri.toString());
                    //In database
                    mAlarmsDatabaseReference.updateChildren(imageUrls).addOnCompleteListener(newOnCompleteListener<Void>() {
                        @OverridepublicvoidonComplete(@NonNull Task<Void> task) {
                            //Progressbar beende + Bild wieder anzeigen
                            progressBar.setVisibility(View.GONE);
                            circleProfilePicture.setVisibility(View.VISIBLE);

                            if(task.isSuccessful()){
                                Toast.makeText(SettingsActivity.this, getResources().getString(R.string.ProfilbildUpdate), Toast.LENGTH_SHORT).show();
                            }else{
                                Toast.makeText(SettingsActivity.this, "FAILED", Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                }
            });
        }
    });

Post a Comment for "Firebase Storage "retrieves A Long Lived Download Url" Using Getdownloadurl() Now Deprecated"