如何修改此代码以将特定用户的图像上传到Firebase,这将创建一个randomUUID。但我想以任何特定的UID上传图片:
StorageReference ref = storageReference.child("Profile/"+ UUID.randomUUID().toString());
ref.putFile(mainImageURI)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
setupProgress.setVisibility(View.INVISIBLE);
//progressDialog.dismiss();
Toast.makeText(SetupActivity.this, "Profile Updated", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
setupProgress.setVisibility(View.INVISIBLE);
//progressDialog.dismiss();
Toast.makeText(SetupActivity.this, "Failed "+e.getMessage(), Toast.LENGTH_SHORT).show();
}
})
.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
setupProgress.setVisibility(View.VISIBLE);
//double progress = (100.0*taskSnapshot.getBytesTransferred()/taskSnapshot.getTotalByteCount());
//progressDialog.setMessage("Uploaded "+(int)progress+"%");
}
});
答案 0 :(得分:1)
您可以在Cloud FireStore或RealTime数据库中为每个正在创建的新用户创建用户配置文件,并将其保存在图像名称中,然后使用Firebase Storage按图像名称将其拉出。