getDownloadUrl()方法不起作用-为什么?

时间:2018-11-28 17:03:26

标签: android firebase-realtime-database firebase-storage

我正在尝试将图像上传到Firebase,但出现此错误:

  

无法解析方法getDownloadUrl()

我浏览了几个主题,但是我无法正确实现针对我的代码提出的解决方案! Firebase对我来说是一个相当新的概念,请尽量不要对我的无知强硬。

我已经花了几个小时来摆弄这段代码,但是我仍然陷于困境。需要帮助

 StorageReference filepath=mStorageReference.child("profile_image").child(uid+".jpg");
            final StorageReference thumb_file_path=mStorageReference.child("profile_image").child("thumbs").child(uid+".jpg");

            //------STORING IMAGE IN FIREBASE STORAGE--------
            filepath.putFile(resultUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {

                    if(task.isSuccessful()){

                        @SuppressWarnings("VisibleForTests")
                       final String downloadUrl=  task.getResult().getDownloadUrl().toString();
                        UploadTask uploadTask = thumb_file_path.putBytes(thumb_bytes);

                        //---------- STORING THUMB IMAGE INTO STORAGE REFERENCE --------
                        uploadTask.addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
                            @Override
                            public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> thumb_task) {
                                @SuppressWarnings("VisibleForTests")
                                String thumb_download_url=thumb_task.getResult().getDownloadUrl().toString();
                                if(thumb_task.isSuccessful()){
                                    Map update_HashMap=new HashMap();
                                    update_HashMap.put("image",downloadUrl);
                                    update_HashMap.put("thumb_image",thumb_download_url);

                                    //--------ADDING URL INTO DATABASE REFERENCE--------
                                    mDatabaseReference.updateChildren(update_HashMap).addOnCompleteListener(new OnCompleteListener<Void>() {
                                        @Override
                                        public void onComplete(@NonNull Task<Void> task) {

                                            if(task.isSuccessful()){
                                                mProgressDialog.dismiss();
                                                Toast.makeText(SettingActivity.this, "Uploaded Successfuly...", Toast.LENGTH_SHORT).show();

                                            }
                                            else{
                                                mProgressDialog.dismiss();
                                                Toast.makeText(getApplicationContext(), " Image is not uploading...", Toast.LENGTH_SHORT).show();

                                            }

                                        }
                                    });

                                }
                                else{
                                    mProgressDialog.dismiss();
                                    Toast.makeText(getApplicationContext(), " Error in uploading Thumbnail..", Toast.LENGTH_SHORT).show();
                                }
                            }
                        });


                    }
                    else{
                        mProgressDialog.dismiss();
                        Toast.makeText(getApplicationContext(), " Image is not uploading...", Toast.LENGTH_SHORT).show();
                    }
                }
            });

        } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {

            Exception error = result.getError();
        }
    }
}

请稍作解释。

随便!

0 个答案:

没有答案