and-nd-firebase icon indicating copy to clipboard operation
and-nd-firebase copied to clipboard

cannot resolve getDownloadUrl please help me out here is the code

Open nandhyalasai opened this issue 6 years ago • 4 comments

public void createOrUpdateProfileWithImage(final Profile profile, Uri imageUri, final OnProfileCreatedListener onProfileCreatedListener) { String imageTitle = ImageUtil.generateImageTitle(UploadImagePrefix.PROFILE, profile.getId()); UploadTask uploadTask = databaseHelper.uploadImage(imageUri, imageTitle);

    if (uploadTask != null) {
        uploadTask.addOnCompleteListener(task -> {
            if (task.isSuccessful()) {


                Uri downloadUrl = task.getResult().getDownloadUrl();  //problem here
                LogUtil.logDebug(TAG, "successful upload image, image url: " + String.valueOf(downloadUrl));

                profile.setPhotoUrl(downloadUrl.toString());
                createOrUpdateProfile(profile, onProfileCreatedListener);

            } else {
                onProfileCreatedListener.onProfileCreated(false);
                LogUtil.logDebug(TAG, "fail to upload image");
            }

        });

nandhyalasai avatar Dec 02 '18 06:12 nandhyalasai

somebody, please notice this.. hehe

real-habibul avatar Dec 16 '18 08:12 real-habibul

+1

fabiorbap avatar Jan 29 '19 23:01 fabiorbap

Hi! you can replace it with this according to the firebase documentation: `Uri selectedImageUri=data.getData();

        final StorageReference photoRef=
                mChatPhotosStorageReference.child(selectedImageUri.getLastPathSegment());

        photoRef.putFile(selectedImageUri).continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
            @Override
            public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
                if (!task.isSuccessful()) {
                    throw task.getException();
                }

                // Continue with the task to get the download URL
                return photoRef.getDownloadUrl();
            }
        }).addOnCompleteListener(new OnCompleteListener<Uri>() {
            @Override
            public void onComplete(@NonNull Task<Uri> task) {
                if (task.isSuccessful()) {
                    Uri downloadUri = task.getResult();
                    FriendlyMessage friendlyMessage= new FriendlyMessage(null,mUsername,downloadUri.toString());
                    mMessagesDatabaseReference.push().setValue(friendlyMessage);
                } else {
                    // Handle failures
                    // ...
                }
            }
        });`

juandgaines avatar Feb 16 '19 15:02 juandgaines

have you found the solution ?, help me please.

gabrielohdez avatar Jun 02 '20 07:06 gabrielohdez