
[英]How can we create a new folder for our app where we can save the downloaded data
[英]How can we auto-generate a new folder for every new user of our android app on Firebase Storage?
当前,正在使用我的Android应用程序的所有用户的数据将转到Firebase Storage上的单个文件夹。 但是我想为每个新设备自动创建一个新文件夹。 也就是说,“ harry的设备”的数据将被上载到Firebase的“ Harry文件夹”中。 并且“简氏设备”的数据将自动上传到“简氏文件夹”。
注意:我想要在Firebase Storage上自动创建文件夹。
不要使用名称,请使用用户的UID,因为它是唯一的。 每当将数据上传到Firebase时,请使用以下命令:
private void uploadMethod() {
progressDialog();
StorageReference storageReferenceProfilePic = firebaseStorage.getReference();
StorageReference imageRef = storageReferenceProfilePic.child(firebaseUser.getUid() + "/" + "image" + ".jpg");
imageRef.putFile(profilePicUri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
//if the upload is successful
//hiding the progress dialog
//and displaying a success toast
dismissDialog();
profilePicUrl = taskSnapshot.getDownloadUrl().toString();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
//if the upload is not successful
//hiding the progress dialog
dismissDialog();
//and displaying error message
Toast.makeText(getActivity(), exception.getCause().getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
})
.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
//calculating progress percentage
// double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
// //displaying percentage in progress dialog
// progressDialog.setMessage("Uploaded " + ((int) progress) + "%...");
}
});
}
当新用户注册到您的应用时,不会自动创建特定的Firebase云存储位置。 但是您可以通过根据用户ID命名文件夹来手动实现此目的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.