-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
On android: progress and begin didn't return any progress #33
Comments
it seems to be you got as same as my problem. when downloading, it got error but not send error event to JS side. could you test this MR? #32 |
but in my case the progress and begin method is not even working once |
I think that DownloadTaskState is stuck in 'PENDING'. For some reason the state is not updating, so the methods (.begin, .done, .progress) never reach the state needed to trigger them. Is this related to introduction of JSI and ditching the Asynchronous bridge? I was experimenting, trying to log state changes in this Objective-C file - RNBackgroundDownloader.m, and it seemed like the native side is ok. |
The issue for me appears to be that an exception is being thrown when the The exception is occurring when trying to estimate the file size which is to be downloaded. This is done with a Here are the logs from the captured exception in
|
In my case, this head request is returning a 401 because the server only respond to authorized requests (even HEAD). In the module entry file, by passing the headers from the Something like public OnBegin(RNBGDTaskConfig config, BeginCallback callback, ReadableMap headers) {
this.config = config;
this.callback = callback;
this.headers = headers;
}
@Override
public OnBeginState call() throws Exception {
HttpURLConnection urlConnection = null;
try {
urlConnection = getConnection(config.url, headers);
Map<String, List<String>> urlHeaders = urlConnection.getHeaderFields();
WritableMap headers = getHeaders(urlConnection, urlHeaders);
urlConnection.getInputStream().close();
long bytesExpected = getContentLength(headers);
callback.onBegin(config.id, headers, bytesExpected);
return new OnBeginState(config.id, headers, bytesExpected);
} catch (Exception e) {
throw new Exception(e);
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
}
} And the private HttpURLConnection getConnection(String urlString, ReadableMap headers) throws Exception {
URL url = new URL(urlString);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
// Requests only headers from the server.
// Prevents memory leaks for invalid connections.
urlConnection.setRequestMethod("HEAD");
if (headers != null) {
ReadableMapKeySetIterator iterator = headers.keySetIterator();
while (iterator.hasNextKey()) {
String headerKey = iterator.nextKey();
String headerValue = headers.getString(headerKey);
urlConnection.setRequestProperty(headerKey, headerValue);
}
}
// 200 and 206 codes are successful http codes.
int httpStatusCode = urlConnection.getResponseCode();
if (httpStatusCode != HttpURLConnection.HTTP_OK && httpStatusCode != HttpURLConnection.HTTP_PARTIAL) {
throw new Exception("HTTP response not valid: " + httpStatusCode);
}
return urlConnection;
} Passing the headers can be the solution (progress is fixed in my case) but there is maybe another solution to calculate the progress without a HEAD request ? |
@kesha-antonov
In Android: im getting the issue that im unable to get the progress of download.
download({
id: jobId,
url: fileUrl,
destination: saveToPath,
metadata: {},
})
.begin(({ expectedBytes, headers }) => {
console.log(
Starting download of ${expectedBytes} bytes
, headers);})
.progress(({ bytesDownloaded, bytesTotal }) => {
console.log(
Download progress: ${bytesDownloaded}% ${bytesTotal}
);The text was updated successfully, but these errors were encountered: