Удаление файла из хранилища Firebase с помощью URL


Здравствуйте, я пытаюсь удалить файл из хранилища Firebase, используя URL-адрес файлов. Моя проблема заключается в том, что getReferenceFromUrl() не может быть решена.

Пример кода здесь:

 StorageReference mStorageRef;
    String storageurl = "http:sample"
    mStorageRef = FirebaseStorage.getInstance().getReference();
        StorageReference ref2 = mStorageRef.getReferenceFromUrl(storageurl);
        ref2.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
            @Override
            public void onSuccess(Void aVoid) {
                // File deleted successfully
                Toast.makeText(getContext(), "file deleted", Toast.LENGTH_SHORT).show();
                Log.d(TAG, "onSuccess: deleted file");
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception exception) {
                // Uh-oh, an error occurred!
                Log.d(TAG, "onFailure: did not delete file");
            }
        });

Любая помощь будет признательна.

3 3

3 ответа:

Попробуйте это я уже пробовал это и его работа

 String storageUrl = "Chat-Images/1498804025000.png";
 StorageReference storageReference = FirebaseStorage.getInstance().getReference().child(storageUrl);
 storageReference.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
      @Override
      public void onSuccess(Void aVoid) {
           // File deleted successfully
           Log.d(TAG, "onSuccess: deleted file");
      }
      }).addOnFailureListener(new OnFailureListener() {
      @Override
      public void onFailure(@NonNull Exception exception) {
            // Uh-oh, an error occurred!
            Log.d(TAG, "onFailure: did not delete file");
         }
      });
 StorageReference storageReference = FirebaseStorage.getInstance().getReferenceFromUrl("https://firebasestorage.googleapis.com/v0/b/***********************-5fac-45b6-bbda-ed4e8a3a62ab");
 storageReference.delete().addOnSuccessListener(new OnSuccessListener<Void>() { 
    @Override 
    public void onSuccess(Void aVoid) {
        // File deleted successfully 
        Log.e("firebasestorage", "onSuccess: deleted file");
    } 
}).addOnFailureListener(new OnFailureListener() { 
    @Override 
    public void onFailure(@NonNull Exception exception) {
        // Uh-oh, an error occurred! 
        Log.e("firebasestorage", "onFailure: did not delete file");
    } 
}); 

Сниппет для удаления файла из хранилища Firebase с помощью URL:

 StorageReference storageReference = FirebaseStorage.getInstance().getReferenceFromUrl("https://firebasestorage.googleapis.com/v0/b/***********************-5fac-45b6-bbda-ed4e8a3a62ab");
    storageReference.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
        @Override
        public void onSuccess(Void aVoid)
            Log.e("firebasestorage", "deleted file");
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) 
            Log.e("firebasestorage", "did not delete file");
        }
    });