将URI存储到Firebase存储

时间:2019-03-18 04:04:30

标签: java firebase firebase-realtime-database firebase-storage

问题

无论我如何更改引用存储的代码,都引用Firebase存储来存储来自摄像机的数据,但会出现空指针异常:

mStorage = FirebaseStorage.getInstance().getReference();
databaseReference = FirebaseDatabase.getInstance().getReference();
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
@Override
protected void onActivityResult ( int requestCode, int resultCode, Intent data){
    buttonNext.setEnabled(true);
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
           uri = data.getData();

        String userId = user.getUid();

        StorageReference filepath = mStorage.child("Users").child(userId).child(Objects.requireNonNull(uri.getLastPathSegment()));

        filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                mProgress.dismiss();

            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {

            }
        });
}

我该如何解决这个问题?

我将存储规则设置为:

  

“允许读写,如果request.auth == null;”

我还可以在每个用户ID下将Firebase Storage文件链接到实时数据库吗?

datbase

0 个答案:

没有答案