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

Unable to download files #15

Closed
taimur97 opened this issue Sep 30, 2015 · 4 comments
Closed

Unable to download files #15

taimur97 opened this issue Sep 30, 2015 · 4 comments

Comments

@taimur97
Copy link

Hi,
Just tried this library and I am not able to download files. I tried downloading from these sites apkleecher.com and www.mp3juices.cc.
It says Download started but the download is never completed and I see small files created in external storage.
Can you please verify it if it is an issue with the library or with the sites?

@taimur97
Copy link
Author

taimur97 commented Oct 3, 2015

And why I have to specify filename. It should fetch the filename from the link

@majidgolshadi
Copy link
Owner

This lib can only download files with direct links that file serve server return file information in response header on library request to download that.
I can't find these features on this server.

@hrdabhi
Copy link

hrdabhi commented Dec 28, 2016

Please add feature to get download file from redirected URL.
This will help you to get actual URL.

`/**
* Http HEAD Method to get actual URL
*
* @param urlString urlString
* @return redirected URL
* @throws IOException
*/
private static String getActualUrl(String urlString) throws IOException {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Accept-Encoding", "");
connection.setRequestMethod("HEAD");
if (isRedirect(connection.getResponseCode())) {
String newUrl = connection.getHeaderField("Location");
System.out.println("newUrl: "+newUrl);
return newUrl;
}
return urlString;
}

/**
 * Check status code for redirects
 *
 * @param statusCode true
 * @return true if matched redirect group
 */
private static boolean isRedirect(int statusCode) {
    if (statusCode != HttpURLConnection.HTTP_OK) {
        if (statusCode == HttpURLConnection.HTTP_MOVED_TEMP
                || statusCode == HttpURLConnection.HTTP_MOVED_PERM
                || statusCode == HttpURLConnection.HTTP_SEE_OTHER) {
            return true;
        }
    }
    return false;
}`

@xeeoon
Copy link

xeeoon commented Feb 5, 2018

@hrdabhi
Thank you for that, it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants