Firebase StorageReference getActiveUploadTasks return 0 results

Viewed 45

I am uploading files in the background in Android. And and to cancel it I store the reference. Now when cancel is clicked and I try to get that upload task from the reference it gives 0 results.

Heres my code:

// Storing the reference
StorageReference storeRef = FirebaseStorage.getInstance().getReference().child("Folder1").child("Folder2").child("Filename")
UploadTask task = storeRef.putFile(file);
intent.putExtra("reference", storeRef.toString());

// Retrieving the UploadTask
final String ref = intent.getStringExtra("reference");
if (ref == null) {
    return;
}

StorageReference sRef = FirebaseStorage.getInstance().getReferenceFromUrl(ref);
List<UploadTask> taskList = sRef.getActiveUploadTasks(); // taskList.size() ---> 0

1 Answers

You may want to start verifying your database connection and see if the reference is done correctly.

If you can discard that, moving to the next step would be to check the upload method is working, maybe a screenshot or simply checking your database in the console inside Firestore is enough if your files are in the cloud.

As you described, you are uploading files in the background. Following the Handle Activity Lifecycle Changes and using your own implementation would be the best option to correct this behaviour.

If you want to check the full example, it is at the end of the same page. Please be aware this example is for uploading from a stream or data in memory apparently, so you need to add the appropriate “uploading from a file” methods.

Continuing with the downloading of the reference, I would redirect to this page for downloads that continue in the background. In both pages, for uploading and downloading the files, you should add the missing code; this is only compared with the code that you already provided, as many parts are still missing. You should read the guide very carefully to avoid skipping any step. And also check the methods are for the correct data type you are using.

Finally, adding a method for handling errors would be great. As in this case you haven’t found the origin of the issue or got any logs to help us debug your code, this could help you save a lot of time and effort in case you encountered yourself with an issue like this one.

Related