即使FireFile方法成功上传文件,也不会调用(Firebase的)addOnSuccessListener

时间:2019-03-10 06:49:52

标签: android firebase file upload

我想将我的android设备的本地文件上传到Firebase存储。

它成功运行。

但是从不调用addOnSuccessListener和addOnFailureListener。

你能让我知道为什么吗?

======================

public void uploadFiles(){

    saveState("uploadFiles");
    StorageReference mStorageRef;
    mStorageRef = FirebaseStorage.getInstance().getReference();
    saveState("Firebase initialize");

    String dirName = Environment.getExternalStorageDirectory().getAbsolutePath();
    dirName += "/Temp";

    File file = new File(dirName);
    files = file.listFiles();
    for (i = 0; i < files.length; i++) {
        if (files[i].isFile() && getFileExtension(files[i]).equals(".3GP")) {
            Uri uri = Uri.fromFile(files[i]);
            StorageReference filepath = mStorageRef.child("Record").child(files[i].getName());
            uploadTask = filepath.putFile(uri);
            uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                    saveState("onSuccess " + files[i].getName());
                }
            });
            uploadTask.addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    saveState("onFailure " + files[i].getName());

                }
            });

            saveState("Success to delete and upload upload " + files[i].getName());
            files[i].delete();
        }
    }
}

0 个答案:

没有答案