diff --git a/android/src/main/java/com/rnfs/DownloadParams.java b/android/src/main/java/com/rnfs/DownloadParams.java index 1b6ac79f..32a81aac 100644 --- a/android/src/main/java/com/rnfs/DownloadParams.java +++ b/android/src/main/java/com/rnfs/DownloadParams.java @@ -12,11 +12,11 @@ public interface OnTaskCompleted { } public interface OnDownloadBegin { - void onDownloadBegin(int statusCode, int contentLength, Map headers); + void onDownloadBegin(int statusCode, long contentLength, Map headers); } public interface OnDownloadProgress { - void onDownloadProgress(int contentLength, int bytesWritten); + void onDownloadProgress(long contentLength, long bytesWritten); } public URL src; diff --git a/android/src/main/java/com/rnfs/DownloadResult.java b/android/src/main/java/com/rnfs/DownloadResult.java index b782bea7..28922d61 100644 --- a/android/src/main/java/com/rnfs/DownloadResult.java +++ b/android/src/main/java/com/rnfs/DownloadResult.java @@ -2,6 +2,6 @@ public class DownloadResult { public int statusCode; - public int bytesWritten; + public long bytesWritten; public Exception exception; } diff --git a/android/src/main/java/com/rnfs/Downloader.java b/android/src/main/java/com/rnfs/Downloader.java index 1177569f..c2d289ac 100644 --- a/android/src/main/java/com/rnfs/Downloader.java +++ b/android/src/main/java/com/rnfs/Downloader.java @@ -19,7 +19,7 @@ import com.facebook.react.bridge.ReadableMapKeySetIterator; -public class Downloader extends AsyncTask { +public class Downloader extends AsyncTask { private DownloadParams mParam; private AtomicBoolean mAbort = new AtomicBoolean(false); DownloadResult res; @@ -64,7 +64,7 @@ private void download(DownloadParams param, DownloadResult res) throws Exception connection.connect(); int statusCode = connection.getResponseCode(); - int lengthOfFile = connection.getContentLength(); + long lengthOfFile = connection.getContentLengthLong(); boolean isRedirect = ( statusCode != HttpURLConnection.HTTP_OK && @@ -85,7 +85,7 @@ private void download(DownloadParams param, DownloadResult res) throws Exception connection.connect(); statusCode = connection.getResponseCode(); - lengthOfFile = connection.getContentLength(); + lengthOfFile = connection.getContentLengthLong(); } if(statusCode >= 200 && statusCode < 300) { Map> headers = connection.getHeaderFields(); @@ -107,7 +107,7 @@ private void download(DownloadParams param, DownloadResult res) throws Exception output = new FileOutputStream(param.dest); byte data[] = new byte[8 * 1024]; - int total = 0; + long total = 0; int count; double lastProgressValue = 0; @@ -116,14 +116,14 @@ private void download(DownloadParams param, DownloadResult res) throws Exception total += count; if (param.progressDivider <= 0) { - publishProgress(new int[]{lengthOfFile, total}); + publishProgress(new long[]{lengthOfFile, total}); } else { double progress = Math.round(((double) total * 100) / lengthOfFile); if (progress % param.progressDivider == 0) { if ((progress != lastProgressValue) || (total == lengthOfFile)) { Log.d("Downloader", "EMIT: " + String.valueOf(progress) + ", TOTAL:" + String.valueOf(total)); lastProgressValue = progress; - publishProgress(new int[]{lengthOfFile, total}); + publishProgress(new long[]{lengthOfFile, total}); } } } @@ -146,7 +146,7 @@ protected void stop() { } @Override - protected void onProgressUpdate(int[]... values) { + protected void onProgressUpdate(long[]... values) { super.onProgressUpdate(values); mParam.onDownloadProgress.onDownloadProgress(values[0][0], values[0][1]); } diff --git a/android/src/main/java/com/rnfs/RNFSManager.java b/android/src/main/java/com/rnfs/RNFSManager.java index 0d11191b..1759c4bd 100755 --- a/android/src/main/java/com/rnfs/RNFSManager.java +++ b/android/src/main/java/com/rnfs/RNFSManager.java @@ -654,7 +654,7 @@ public void onTaskCompleted(DownloadResult res) { infoMap.putInt("jobId", jobId); infoMap.putInt("statusCode", res.statusCode); - infoMap.putInt("bytesWritten", res.bytesWritten); + infoMap.putDouble("bytesWritten", (double)res.bytesWritten); promise.resolve(infoMap); } else { @@ -664,7 +664,7 @@ public void onTaskCompleted(DownloadResult res) { }; params.onDownloadBegin = new DownloadParams.OnDownloadBegin() { - public void onDownloadBegin(int statusCode, int contentLength, Map headers) { + public void onDownloadBegin(int statusCode, long contentLength, Map headers) { WritableMap headersMap = Arguments.createMap(); for (Map.Entry entry : headers.entrySet()) { @@ -675,7 +675,7 @@ public void onDownloadBegin(int statusCode, int contentLength, Map