我正在使用以下代码将图像上传到Firebase存储,并使用以下代码从Firebase存储中检索图像链接

时间:2019-11-20 05:00:57

标签: android firebase firebase-storage

我想检索存储在Firebase存储器中的图像的链接,并将其存储在“ Profile_Image”节点下的Firebase数据库中,但是我得到了一些虚拟文本。 图片中给出了原始链接和我正在获取的链接...请有人帮助我... 图片链接已给定[[1]:https://i.stack.imgur.com/sTak1.png][1]

{

Uri resulUri=result.getUri();
StorageReference filePath=userProfileImageReference.child(currentUserId + ".jpg");
filePath.putFile(resulUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
                @Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
                    if (task.isSuccessful())
                    {
                        Toast.makeText(SetupActivity.this, "Image is Uploaded Successfully to 
Firebase Storage... ", Toast.LENGTH_SHORT).show();

                        final String downloadUrl = 
task.getResult().getStorage().getDownloadUrl().toString();
                        userRef.child("Profile_Image").setValue(downloadUrl)
                                .addOnCompleteListener(new OnCompleteListener<Void>() {
                                    @Override
                                    public void onComplete(@NonNull Task<Void> task) {
                                        if (task.isSuccessful())
                                        {
                                            Intent selfIntent=new 
Intent(SetupActivity.this,SetupActivity.class);
                                            startActivity(selfIntent);
                                            Toast.makeText(SetupActivity.this, "Profile Image stored 
successfully to Firebase Database...", Toast.LENGTH_SHORT).show();
                                            loadingBar.dismiss();
                                        }
                                        else
                                        {
                                            String message=task.getException().getMessage();
                                            Toast.makeText(SetupActivity.this, "Error Occurred 
"+message, Toast.LENGTH_SHORT).show();
                                            loadingBar.dismiss();
                                        }
                                    }
                                });
                    }
                }
            }); }

0 个答案:

没有答案