android - 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 中。
任何帮助都会被评估
解决方案
您传递的常量配置文件 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
}
推荐阅读
- mongodb - 升级到 Spring Boot Mongodb 2.2.X 隐藏 GeoNear Aggregate 管道结果超过 100 条记录
- regex - Bash:从测试字符串中提取第二个整数
- javascript - 在一个 WebGL 画布中渲染多个视频流
- google-chrome - 基于 EXIF 在 Chrome 中从文件绘制照片到画布旋转
- c++ - 移动 std::unique_ptr 的构造函数/赋值:内存重新分配?
- google-cloud-storage - AndroidX Camera Core ImageAnalysis.Analyser 导致图像失真
- unity3d - unity GUID 在不同计算机上是否唯一?
- node.js - 无法使用 Knex.js 迁移验证用户:Node 中的最新版本
- python - argparse — 查明是否提供了参数或使用了默认值
- java - Omnet++ 中的模拟时间