Hi,
I've just started using Fetch and it seems exactly what I was looking for, but I'm facing a problem. I've seen that the library doesn't call FetchListener -> onCompleted() when downloading a file with an unknown length. The file is downloaded correctly, but the downloader doesn't know that it has finished. In my case, the server I'm connecting to is not including the header 'Content-Length' in the responses. Instead, it is including the header 'Transfer-Encoding' to 'chunked' (I've checked that this is the problem).
That should be not an issue, since I can make the same request using OkHttp3 without a problem. Because of this, I used fetch2okhttp as the downloader, but the result is the same, so I guess is a problem with the implementation of the class Downloader or I am missing something. Also, I'm not familiar with Kotlin, so I can't move through the code very easely.
Any hint?
Thanks.
FetchConfiguration fetchConfiguration = new FetchConfiguration.Builder(App.getContext())
.setHttpDownloader(new OkHttpDownloader())
.build();
Fetch fetch = Fetch.Impl.getInstance(fetchConfiguration);
String url = "https://www.httpwatch.com/httpgallery/chunked/chunkedimage.aspx?0.01891488106459449";
String file = App.getContext().getFilesDir() + "/" + "chunked.jpg";
Request request = new Request(url, file);
request.setPriority(Priority.HIGH);
request.setNetworkType(NetworkType.ALL);
fetch.enqueue(request, null, null);
fetch.addListener(new AbstractFetchListener() {
... // onCompleted() is not fired
});
That should be not an issue, since I can make the same request using OkHttp3 without a problem
Try to use your okhttpclient that works:
OkHttpClient customOkHttpClient = new OkHttpClient();
FetchConfiguration fetchConfiguration = new FetchConfiguration.Builder(App.getContext())
.setHttpDownloader(new OkHttpDownloader(customOkHttpClient))
.build();
The OkHttp3 client that was working for me was exactly that, the default client with no further settings. Passing it as an argument for the constructor of OkHttpDownloader doesn't fix the problem, though.
@sysseon ill take a look at the issue tomorrow and will update this post.
@sysseon I was able to replicate this bug. Working on a fix
any luck? I got stuck on onCompleted() not firing :( I need it
11-02 11:28:04.931 10640-10720/? W/OkHttpClient: A connection to http://mysite.sk/ was leaked. Did you forget to close a response body?
... if this helps
@sethchhim @sysseon Was on vacation. hoping to release the new version sometime today or tomorrow. Please check back later.
cheers, I tried to fix that, but I failed...need to get more knowledge on Kotlin, though...
anyways, as I googled, I noticed it's most importantly a server side issue, so we turned off gzip on it, and downloads now working...but if you found a way to resolve this issue with no ContentLength returned, that's brilliant...thank you!!!
Please update, it's a major problem that renders the library useless for us and I don't want to change libraries..
@sysseon @sethchhim @mariaanko @Shailevy Just released a new Fetch version. 2.3.0-RC1. This version has lots of fixes and breaking changes so be sure to check out the CHANGELOG.
This bug should now be fixed for both Parallel and Sequential Downloaders. Please let me know if it works well for you.
Working perfect now! Thanks a lot Tonyo!
Most helpful comment
@sysseon @sethchhim @mariaanko @Shailevy Just released a new Fetch version. 2.3.0-RC1. This version has lots of fixes and breaking changes so be sure to check out the CHANGELOG.
This bug should now be fixed for both Parallel and Sequential Downloaders. Please let me know if it works well for you.