I have the following code snippet in my onSuccessListener() to save the download URL of the file I uploaded.
DatabaseReference downloadURLRef = rootRef.child("Child").child(value);
Uri downloadUrl = taskSnapshot.getDownloadUrl();
downloadURLRef.setValue(downloadUrl);
I get this error:
Error TaskSnapshot - Method should only be accessed within private scope while using android studio 2.3.
When I followed this post and suppressed the warning, my app crashes on upload, and the upload fails. Here's the error for that.
What gives? This is straight from the Firebase documentation too.
EDIT: Upload code.
storage = FirebaseStorage.getInstance();
storageRef = storage.getReference(date + "/" + filename);
uploadTask = storageRef.putFile(Uri.fromFile(file));
// Register observers to listen for when the download is done or if it fails
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle unsuccessful uploads
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// TODO: Fix this bullshit
DatabaseReference downloadURLRef = rootRef.child("Child").child(value);
Uri downloadUrl = taskSnapshot.getDownloadUrl();
downloadURLRef.setValue(downloadUrl);
}
});