Skip to content
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

added additional download input parameters readTimeout and connectionTimeout #301

Merged
merged 1 commit into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion FS.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type DownloadFileOptions = {
headers?: Headers; // An object of headers to be passed to the server
background?: boolean; // iOS only
progressDivider?: number;
readTimeout?: number;
connectionTimeout?: number;
begin?: (res: DownloadBeginCallbackResult) => void;
progress?: (res: DownloadProgressCallbackResult) => void;
};
Expand Down Expand Up @@ -382,6 +384,8 @@ var RNFS = {
if (options.headers && typeof options.headers !== 'object') throw new Error('downloadFile: Invalid value for property `headers`');
if (options.background && typeof options.background !== 'boolean') throw new Error('downloadFile: Invalid value for property `background`');
if (options.progressDivider && typeof options.progressDivider !== 'number') throw new Error('downloadFile: Invalid value for property `progressDivider`');
if (options.readTimeout && typeof options.readTimeout !== 'number') throw new Error('downloadFile: Invalid value for property `readTimeout`');
if (options.connectionTimeout && typeof options.connectionTimeout !== 'number') throw new Error('downloadFile: Invalid value for property `connectionTimeout`');

var jobId = getJobId();
var subscriptions = [];
Expand All @@ -400,7 +404,9 @@ var RNFS = {
toFile: normalizeFilePath(options.toFile),
headers: options.headers || {},
background: !!options.background,
progressDivider: options.progressDivider || 0
progressDivider: options.progressDivider || 0,
readTimeout: options.readTimeout || 15000,
connectionTimeout: options.connectionTimeout || 5000
};

return {
Expand Down
2 changes: 2 additions & 0 deletions android/src/main/java/com/rnfs/DownloadParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public interface OnDownloadProgress {
public File dest;
public ReadableMap headers;
public float progressDivider;
public int readTimeout;
public int connectionTimeout;
public OnTaskCompleted onTaskCompleted;
public OnDownloadBegin onDownloadBegin;
public OnDownloadProgress onDownloadProgress;
Expand Down
4 changes: 2 additions & 2 deletions android/src/main/java/com/rnfs/Downloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ private void download(DownloadParams param, DownloadResult res) throws Exception
connection.setRequestProperty(key, value);
}

connection.setConnectTimeout(5000);
connection.setReadTimeout(15000);
connection.setConnectTimeout(param.connectionTimeout);
connection.setReadTimeout(param.readTimeout);
connection.connect();

int statusCode = connection.getResponseCode();
Expand Down