error: can not find symbol method getDownloadUrl ()

0

Hello I can not find out what the problem is with this error, this is the code snippet that I use:

 if (task.isSuccessful()) {
                        FriendlyMessage friendlyMessage =
                                new FriendlyMessage(null, mUsername, 
       mPhotoUrl,
                                        task.getResult().getDownloadUrl()
                                                .toString(), 
   user.getData().getID(), Calendar.getInstance().getTimeInMillis());

        mFirebaseDatabaseReference.child
       (THREAD_CHILD).child(path).child(MESSAGE_CHILD).child(key)
                          .setValue(friendlyMessage);
                    } else {
                        Log.w(TAG, "Image upload task was not successful.",
                                task.getException());
                    }
    
asked by Manu Abella 08.10.2018 в 15:36
source

1 answer

0

If your intention is to upload a photo or file to Firebase Storage, get the url and put it in the database you should do the following

  //En este caso guardamos la foto en el storage bajo la siguiente direccion -- fotos -- userUID -- nombre de la foto tomada
StorageReference fileReference = mStorageReference.child("fotos").child(mAuth.getCurrentUser().getUid()).child(filePath.getLastPathSegment());
fileReference.putFile(filePath).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();
                    }
                    //Devolvemos la url de descarga
                    return mStorageReference.getDownloadUrl();
                }
            }).addOnCompleteListener(new OnCompleteListener<Uri>() {
                @Override
                public void onComplete(@NonNull Task<Uri> task) {
                    if (task.isSuccessful()) {
                        //Obtenemos la url descarga
                        Uri downloadUri = task.getResult();
                        Log.e(TAG, "onComplete: Success " );
                        //La ponemos en el database
                       mFirebaseDatabaseReference.child
   (THREAD_CHILD).child(path).child(MESSAGE_CHILD).child(key)
                      .setValue(friendlyMessage);

                    } else {
                        Toast.makeText(mContext, "upload failed: " + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
                    }
                }
            });

This code will be useful to upload a photo to your Storage, get the download link and put it in a reference in your Database. As I saw in your question, you return a message that the photo could not be uploaded, so you must be doing that.

where mStorageReference is

StorageReference mStorageReference;
mStorageReference = FirebaseStorage.getInstance().getReference();
    
answered by 11.10.2018 в 19:00