Skip to content

Commit aa542c8

Browse files
authored
Merge pull request itinance#301 from drunksaint/added_timeout_params
added additional download input parameters readTimeout and connectionTimeout
2 parents 98b108d + a159776 commit aa542c8

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

FS.common.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ type DownloadFileOptions = {
6060
headers?: Headers; // An object of headers to be passed to the server
6161
background?: boolean; // iOS only
6262
progressDivider?: number;
63+
readTimeout?: number;
64+
connectionTimeout?: number;
6365
begin?: (res: DownloadBeginCallbackResult) => void;
6466
progress?: (res: DownloadProgressCallbackResult) => void;
6567
};
@@ -382,6 +384,8 @@ var RNFS = {
382384
if (options.headers && typeof options.headers !== 'object') throw new Error('downloadFile: Invalid value for property `headers`');
383385
if (options.background && typeof options.background !== 'boolean') throw new Error('downloadFile: Invalid value for property `background`');
384386
if (options.progressDivider && typeof options.progressDivider !== 'number') throw new Error('downloadFile: Invalid value for property `progressDivider`');
387+
if (options.readTimeout && typeof options.readTimeout !== 'number') throw new Error('downloadFile: Invalid value for property `readTimeout`');
388+
if (options.connectionTimeout && typeof options.connectionTimeout !== 'number') throw new Error('downloadFile: Invalid value for property `connectionTimeout`');
385389

386390
var jobId = getJobId();
387391
var subscriptions = [];
@@ -400,7 +404,9 @@ var RNFS = {
400404
toFile: normalizeFilePath(options.toFile),
401405
headers: options.headers || {},
402406
background: !!options.background,
403-
progressDivider: options.progressDivider || 0
407+
progressDivider: options.progressDivider || 0,
408+
readTimeout: options.readTimeout || 15000,
409+
connectionTimeout: options.connectionTimeout || 5000
404410
};
405411

406412
return {

android/src/main/java/com/rnfs/DownloadParams.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public interface OnDownloadProgress {
2323
public File dest;
2424
public ReadableMap headers;
2525
public float progressDivider;
26+
public int readTimeout;
27+
public int connectionTimeout;
2628
public OnTaskCompleted onTaskCompleted;
2729
public OnDownloadBegin onDownloadBegin;
2830
public OnDownloadProgress onDownloadProgress;

android/src/main/java/com/rnfs/Downloader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ private void download(DownloadParams param, DownloadResult res) throws Exception
5656
connection.setRequestProperty(key, value);
5757
}
5858

59-
connection.setConnectTimeout(5000);
60-
connection.setReadTimeout(15000);
59+
connection.setConnectTimeout(param.connectionTimeout);
60+
connection.setReadTimeout(param.readTimeout);
6161
connection.connect();
6262

6363
int statusCode = connection.getResponseCode();

0 commit comments

Comments
 (0)