diff --git a/android/src/main/java/com/rnfs/Downloader.java b/android/src/main/java/com/rnfs/Downloader.java index 3c36736..954c5fb 100644 --- a/android/src/main/java/com/rnfs/Downloader.java +++ b/android/src/main/java/com/rnfs/Downloader.java @@ -50,6 +50,24 @@ public class Downloader extends AsyncTask int statusCode = connection.getResponseCode(); int lengthOfFile = connection.getContentLength(); + boolean isRedirect = ( + statusCode != HttpURLConnection.HTTP_OK && + ( + statusCode == HttpURLConnection.HTTP_MOVED_PERM || + statusCode == HttpURLConnection.HTTP_MOVED_TEMP + ) + ); + + if (isRedirect) { + String redirectURL = connection.getHeaderField("Location"); + connection = (HttpURLConnection) new URL(redirectURL).openConnection(); + connection.setConnectTimeout(5000); + connection.connect(); + + statusCode = connection.getResponseCode(); + lengthOfFile = connection.getContentLength(); + } + Map> headers = connection.getHeaderFields(); Map headersFlat = new HashMap();