Firebase存储未在子android上创建新文件夹

问题描述 投票:0回答:1

我尝试通过唯一值(auth UID)为每个用户创建文件夹。我做到了:

        private String profileId;
        private StorageReference mStorageRef;

  @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle bundle = this.getArguments();
        profileId = bundle.getString(Constants.PROFILE_ID_KEY);
        mStorageRef = FirebaseStorage.getInstance().getReference("images");

        StorageReference imageStorageRef = mStorageRef.child(profileId);

        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            String imageName = "img" + timeStamp + "_.jpg";

            imageStorageRef.child(imageName).putFile(picUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                    Uri downloadUrl = taskSnapshot.getUploadSessionUri();
                }
            })
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {

                        }
                    });
    }

即使我退出并与其他profileId连接,也会将所有图像放入特定的profileId中。任何帮助都会得到评估

android firebase firebase-storage
1个回答
0
投票

您通过的常量配置文件ID:profileId = bundle.getString(Constants.PROFILE_ID_KEY);

而不是仅通过使用Firebase身份验证直接获得用户。

if(FirebaseAuth.getInstance().getCurrentUser() != null){
    uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
}else{
    //do what you want
}
© www.soinside.com 2019 - 2024. All rights reserved.