1

Try to get URL of image uploaded in Firebase Storage, using this docs, but there's no info about how to return downloadUri value from Task.continueWithTask method.

Even method documentation doesn't helped to understand.

Quote from docs, there's no explanation how to get this URL:

After uploading a file, you can get a URL to download the file by calling the getDownloadUrl() method on the StorageReference:

final StorageReference ref = storageRef.child("images/mountains.jpg");
        uploadTask = ref.putFile(file);

        Task<Uri> urlTask = uploadTask.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 ref.getDownloadUrl();
            }
        }).addOnCompleteListener(new OnCompleteListener<Uri>() {
            @Override
            public void onComplete(@NonNull Task<Uri> task) {
                if (task.isSuccessful()) {
                    Uri downloadUri = task.getResult();
                } else {
                    // Handle failures
                    // ...
                }
            }
        });
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • It looks like you've written code that gets the download URL, so I don't really understand what the problem is here. – Doug Stevenson Feb 19 '19 at 23:46
  • I re-writed [my question](https://stackoverflow.com/questions/54785290/continuewithtask-method-doesnt-start), the problem is that `continueWithTask` doesn't start. Can you help? – Vadim Bugakov Feb 20 '19 at 18:12

2 Answers2

1

I haven't used Firebase for a while, but the way I used to do it is to assign either a SuccessListener or OnCompleteListener after calling ref.getDownloadUrl()

Example

ref.getDownloadUrl().addOnSuccessListener(url -> {
    ...
});
jbmcle
  • 771
  • 3
  • 12
0

To retrieve the URL of the image or the data you have stored in firestore you should use OnSuccessListener

Like

     firepath.putFile(resultUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {     
@Override

public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

    firepath.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {

@Override
public void onSuccess(Uri uri) {
final String url = uri.toString();
 }});});

Here string URL will have the link of the image or the video

saibhaskar
  • 435
  • 6
  • 21