Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8756923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:11:07+00:00 2026-06-13T14:11:07+00:00

I need to download a file from a URL except I don’t know what

  • 0

I need to download a file from a URL except I don’t know what type the file will be and the URL I am using doesn’t have /random.file at the end of it so I can’t parse the url for the filename.
At the moment I’m using the Android download manager which works greats and means I don’t have handle the download but I can’t see anyway to get the file name out of the file its downloading. If I load the same url in Firefox for example it asks ‘Download file: Nameoffile.extension’.

Is there a way for me to replicate this behaviour and get the file name before I download the file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:11:08+00:00Added an answer on June 13, 2026 at 2:11 pm

    I ended up using an ASyncTask to manually retrieve the file name and passing it to the download manager, if it helps anyone this is how I did it (my url went through a number of redirects before the actual file download):

    class GetFileInfo extends AsyncTask<String, Integer, String>
    {
        protected String doInBackground(String... urls)
        {
                    URL url;
                    String filename = null;
                    try {
                        url = new URL(urls[0]);
                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                    conn.connect();
                    conn.setInstanceFollowRedirects(false); 
    
                    try {
                        for(int i = 0; i < 10; i++)
                        {
                            url = new URL(conn.getHeaderField("Location")); 
                            conn = (HttpURLConnection) url.openConnection();
                            conn.connect();
                            conn.setInstanceFollowRedirects(false);
                        }
                    } catch (Exception e) {
                    }
    
                    String depo = conn.getHeaderField("Content-Disposition");
                    String depoSplit[] = depo.split(";");
                    int size = depoSplit.length;
                    for(int i = 0; i < size; i++)
                    {
                        if(depoSplit[i].startsWith("filename="))
                        {
                            filename = depoSplit[i].replace("filename=", "").replace("\"", "").trim();
                            Global.error(filename);
                            i = size;
                        }
                    }
                    } catch (MalformedURLException e1) {
                        e1.printStackTrace();
                    } catch (IOException e) {
                    }
                return filename;
        }
    
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }
    
        @Override
        protected void onProgressUpdate(Integer... progress) {
            super.onProgressUpdate(progress);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application i need to download pdf file from url.i know how to
I need to download a Cab file from a Url into a stream. using
I'm using vb.net and need to download a file (from a given URL). The
I need to download one file from an url that i give from an
I need to download a file from a url which has format similar to
I need to download a mp3 file from a server URL, and then play
I need to download a .mp3 or .m4a file from the server by using
I need to download a file from an url and save it to local
In my application I need to download a .fec file from an Url and
I have a vb script to download a file from an URL - the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.