I download a file using fetch i get Complete callback and file gets save/created in memory but with 0 bytes
String finalPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + Constants.MEERA_APPS_PATH + File.separator + fileName;
final Request request = new Request(downloadPath, finalPath);
request.setPriority(Priority.HIGH);
request.setNetworkType(NetworkType.ALL);
request.addHeader("Authorization", "Bearer " + DataHolder.getInstance().getUser().token.access_token);
fetch.enqueue(request, updatedRequest -> {
//Request was successfully enqueued for download.
mDownloadListener.onDownloadEnQueued();
}, error -> {
//An error occurred enqueuing the request.
mDownloadListener.onDownloadError(error);
});
fetch.addListener(fetchListener);
Any help?
@nomizodiac It would be hard to say what the issue is with only the request information. Have you tried downloading the file on a physical device or emulator? Are the results always the same?. Also, try a different downloadPath to see if you get the same results.
I have a similar problem. When I start the app for the first time with a new save path it downloads the file as expected. When starting the app the second time the file download completes but the file has 0 bytes.
Deleting the file (either manually or in code) before retrying to download does not change the outcome.
Any ideas what could be the problem here?
Update:
calling removeAll() on the Fetch object solves this issue for me. Looks like the object still contains the downloads from the previous session?
Confirmed:
com.tonyodev.fetch2:fetch2:3.0.11
Still an issue. onComplete fires but the fileUri is 0 bytes.
Simulator, device doesnt matter.
I had a similar issue where the fetch instance contained already finished downloads. As @FelixBurkhard mentioned I had to remove the downloads from it. E.g. call removeAll() or remove(downloadId). Now everything works fine.
i have same issue with onCompleted event it fired when we have network failure ?
If someone can provide any steps or code to reproduce this issue it would help me narrow down the problem more quickly.
A new version of Fetch 3.0.12 & AndroidX version 3.1.6 has been released
I have the issue with http://195.85.182.90:52633/AndroidAPI/AuthList/20_20210107_155300.gz
When using same path, onCompleted gets called even when no internet, after the first real download.
file = new File(getFilesDir(), "csv.gz");
Request request = new Request(url, Uri.fromFile(file));
@arosca-nl If the download already exist and completed Fetch will always call onCompleted. You will first have to delete the request by calling fetch.delete()