I have something Like this.
...
fileFetcher = new Fetch.Builder(this, "Main").enableLogging(true).setDownloadConcurrentLimit(4).build();
...
public Request createRequest(url,name){
Request request = new Request(url, name);
request.setPriority(Priority.NORMAL);
request.setGroupId(10001);
request.setNetworkType(NetworkType.WIFI_ONLY);
return request;
}
...
fileFetcher.enqueue(requests, new Func<List<? extends Download>>() {
@Override
public void call(List<? extends Download> downloads) {
Log.v("FILEDOWNLOAD", "ENQUED SUCCESSFULLY");
}
}, new Func<Error>() {
@Override
public void call(Error error) {
Log.e("FILEDOWNLOAD", "Error While Enqueing Requests");
Log.e("FILEDOWNLOAD", error.toString());
}
});
...
//I am Getting the Following Error when I En-queue them via the list. Or Even when I do them Separately. Why?
E/FILEDOWNLOAD: Error While Enqueing Requests
REQUEST_WITH_ID_ALREADY_EXIST
@LaserStony Fetch stores all request in a database(This is used to manage downloads). If the database already has a request with the same id request.getId() or a request with the same url request.getUrl(), Fetch will reject the new request and you will get an error. As of version 2.0.0-RC19, you can tell Fetch to replace an existing request without you having to manually remove them with Fetch.remove(request.getId()).
Solution: Add the RequestOptions.RequestOptions.REPLACE_ALL_ON_ENQUEUE_WHERE_UNIQUE or RequestOptions.REPLACE_ALL_ON_ENQUEUE_WHERE_UNIQUE_FRESH on the Fetch Builder. These options first removes any requests in the database that matches the enqueuing request's id or file. FRESH will force a download from the beginning. See the Java Docs for RequestOptions.
Example:
final Fetch fetch = new Fetch.Builder(this, "namespace")
.setLogger(new FetchTimberLogger())
.setDownloader(new OkHttpDownloader())
.setDownloadConcurrentLimit(4)
.enableLogging(true)
.enableRetryOnNetworkGain(true)
.addRequestOptions(RequestOptions.REPLACE_ALL_ON_ENQUEUE_WHERE_UNIQUE_FRESH)
.build();
Most helpful comment
@LaserStony Fetch stores all request in a database(This is used to manage downloads). If the database already has a request with the same id
request.getId()or a request with the same urlrequest.getUrl(), Fetch will reject the new request and you will get an error. As of version2.0.0-RC19, you can tell Fetch to replace an existing request without you having to manually remove them withFetch.remove(request.getId()).Solution: Add the
RequestOptions.RequestOptions.REPLACE_ALL_ON_ENQUEUE_WHERE_UNIQUEorRequestOptions.REPLACE_ALL_ON_ENQUEUE_WHERE_UNIQUE_FRESHon the Fetch Builder. These options first removes any requests in the database that matches the enqueuing request's id or file.FRESHwill force a download from the beginning. See the Java Docs for RequestOptions.Example: