首页 > 解决方案 > firebase 存储未在子 android 上创建新文件夹

问题描述

我尝试通过唯一值(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 中。
任何帮助都会被评估

标签: androidfirebasefirebase-storage

解决方案


您传递的常量配置文件 id :profileId = bundle.getString(Constants.PROFILE_ID_KEY);

而不是直接通过使用 firebase auth 来获取用户。

if(FirebaseAuth.getInstance().getCurrentUser() != null){
    uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
}else{
    //do what you want
}

推荐阅读