使用文件下载URI从Firebase删除文件?

时间:2018-10-02 08:26:21

标签: android file firebase firebase-storage

如何从Firebase存储中删除文件? 我只有下载URI(String)的文件,如何从火源存储中删除文件? 我试图将我的下载字符串解析为uri,并尝试将存储引用引用到该uri,但这没有用

private void image_delete(int i){
         for(;i<=3;i++){
            image_path[i]=image_path[i+1];
            if(image_path[i+1]==null)
                img[i].setImageResource(R.drawable.camera);
            else
            Picasso.get().load(image_path[i+1]).into(img[i]);
            image_path[i]=image_path[i+1];
            img[i+1].setImageResource(R.drawable.camera);
            if(image_path[i+1]==null)
                break;
        }
        if(i!=4)
        image_body[i+1].setVisibility(View.GONE);
        image_path[i]=null;
        storageReference=FirebaseStorage.getInstance().getReference();
        storageReference.child("Pets").child(image_path[i].substring(image_path[i].indexOf("/Pets")+4,image_path[i].length()));
        storageReference.delete();
        upload_status.setText("");
    }

1 个答案:

答案 0 :(得分:0)

要使用 URL Firebase 存储中删除任何文件:

 String url= "Chat-Images/1498804025000.png";

 StorageReference storageReference = 
 FirebaseStorage.getInstance().getReference().child(url);

 storageReference.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
      @Override
      public void onSuccess(Void aVoid) {
           Log.d(TAG, "onSuccess: deleted file successfully");
      }
      }).addOnFailureListener(new OnFailureListener() {

      @Override
      public void onFailure(@NonNull Exception exception) {
            Log.d(TAG, "onFailure: File is not delete!");
         }
      });

原始答案:https://stackoverflow.com/a/45103937/9093630