Esben Eickhardt
Esben Eickhardt

Reputation: 3872

Download file from url with no specified filename

I would like to download a file from a url where the filename is not specified. If i type this url (https://www.cpr.dk/vejregister) into the browser it downloads the correct file.

If I write this code only the header is downloaded:

# In R
download.file(url = "https://www.cpr.dk/vejregister",
              destfile = "/data/kkgrunddata/Vejdata/vejdata_latest",
              method='curl')

# In BASH
>more vejdata_latest

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/media/21570/vejregister_hele_landet_pr_181201.zip">here</a>.</h2>
</body></html>

Do you have any suggestions of how to download the file without specifying the filename from the header?

Upvotes: 0

Views: 601

Answers (1)

user7788121
user7788121

Reputation:

I was able to reproduce the issue with your code. Upon removing the method='curl' argument, I got it to download without specifying the link in the header.

download.file(url = "https://www.cpr.dk/vejregister",
          destfile = "./vejdata_latest")

Edit: If you're on Windows, don't forget the file extension (.zip in this case)

Upvotes: 1

Related Questions