的firebase上传解决方案无法在firebase中的child()错误中为参数'pathString'传递null

时间:2018-10-24 10:43:06

标签: android firebase

我正在尝试将Firebase中的pdf文档上载到子目录中。 但是我收到这个错误

protected void onCreate(Bundle savedInstanceState) {


   super.onCreate(savedInstanceState);


    setContentView(R.layout.activity_main);

    mStorageReference = FirebaseStorage.getInstance().getReference();

    mDatabaseReference = FirebaseDatabase.getInstance().getReference(FirebaseAuth.getInstance().getCurrentUser().getUid()).child(selectedItemText);

    firebaseAuth = FirebaseAuth.getInstance();



    spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {


        @Override


     public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
             selectedItemText = (String) parent.getItemAtPosition(position);


     // Notify the selected item text


     textViewSem.setText(selectedItemText);


}


private void uploadFile(Uri data) {


    progressBar.setVisibility(View.VISIBLE);


        //StorageReference sRef = 


    mStorageReference.child(conastants.STORAGE_PATH_UPLOADS + 


    System.currentTimeMillis() + ".pdf");


    StorageReference sRef =mStorageReference.child(FirebaseAuth.getInstance().getCurrentUser().getUid()).


    child(selectedItemText + "/" + System.currentTimeMillis() + ".pdf");


    sRef.putFile(data).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {


       @SuppressWarnings("VisibleForTests")


       @Override


public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {


       progressBar.setVisibility(View.GONE);


       textViewStatus.setText("File Uploaded Successfully");

       sems = selectedItemText;



       Uploads upload = new Uploads(editTextFilename.getText().toString(), taskSnapshot.getDownloadUrl().toString());

 mDatabaseReference.child(mDatabaseReference.push().getKey()).setValue(upload);




                    }


                })


                .addOnFailureListener(new OnFailureListener() {
                    @Override

public void onFailure(@NonNull Exception exception) {


     Toast.makeText(getApplicationContext(), exception.getMessage(), Toast.LENGTH_LONG).show();


  }


  }).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {


         @SuppressWarnings("VisibleForTests")


         @Override


         public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {


                double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();




                textViewStatus.setText((int) progress + "% Uploading...");


      }


    });



}

0 个答案:

没有答案