Firebase Storage “retrieves a long lived download URL” using getDownloadUrl() now deprecated

后端 未结 3 389
清酒与你
清酒与你 2020-12-06 08:32

This getDownloadUrl() method showed deprecated after updating to

\'com.google.firebase:firebase-storage:15.0.2\'

相关标签:
3条回答
  • 2020-12-06 09:25

    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()

    0 讨论(0)
  • 2020-12-06 09:27

    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(new OnSuccessListener<Uri>() {
                    @Override
                    public void onSuccess(Uri uri) {
                        Map imageUrls = new HashMap();
                        imageUrls.put("image", fullImageUrl);
                        imageUrls.put("thumb_image", uri.toString());
                        //In database
                        mAlarmsDatabaseReference.updateChildren(imageUrls).addOnCompleteListener(new OnCompleteListener<Void>() {
                            @Override
                            public void onComplete(@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();
                                }
                            }
                        });
                    }
                });
            }
        });
    
    0 讨论(0)
  • 2020-12-06 09:31
      final StorageReference filePath = mImageStore.child("profile_images").child("full_image").child(userId + ".jpg");
                    filePath.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                        @Override
                        public void onSuccess(Uri uri) {
                            //Bitmap hochladen
                            uploadBitMap(uri.toString());
                        }
                    });strong text
    

    Or

    final UploadTask uploadTask = thumb_file.putBytes(thumb_bite);
            uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
    
                    //Url laden
                    taskSnapshot.getStorage().getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                        @Override
                        public void onSuccess(Uri uri) {
                            Map imageUrls = new HashMap();
                            imageUrls.put("image", fullImageUrl);
                            imageUrls.put("thumb_image", uri.toString());
                            //In database
                            mAlarmsDatabaseReference.updateChildren(imageUrls).addOnCompleteListener(new OnCompleteListener<Void>() {
                                @Override
                                public void onComplete(@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();
                                    }
                                }
                            });
                        }
                    });
                }
            });
    
    0 讨论(0)
提交回复
热议问题