# How do I use Downloads.download to download to a custom location?

**URL:** <https://discourse.julialang.org/t/how-do-i-use-downloads-download-to-download-to-a-custom-location/75322>\
**Category:** New to Julia\
**Tags:** libcurl\
**Created:** [January 27, 2022, 8:23pm UTC](https://discourse.julialang.org/t/how-do-i-use-downloads-download-to-download-to-a-custom-location/75322 "2022-01-27T20:23:45Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![thompsonmj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thompsonmj/32/25172_2.png) [@thompsonmj](https://discourse.julialang.org/u/thompsonmj)\
**Post date:** [January 27, 2022, 8:23pm UTC](https://discourse.julialang.org/t/how-do-i-use-downloads-download-to-download-to-a-custom-location/75322/1 "2022-01-27T20:23:45Z")

</div>

In the docs for [Downloads.download](https://docs.julialang.org/en/v1/stdlib/Downloads/#Downloads.download), there are no examples and the errors don’t help.

For instance, I’m trying to download a `Projects.toml` file from another repository.

```julia
julia> project_url = "https://raw.githubusercontent.com/JuliaDynamics/DrWatson.jl/master/Project.toml"
julia> project_file = Downloads.download(project_url)

```

This goes to an auto-created temporary path, as the docs say. But I can’t understand the following to put it in a custom path:

```julia
download(url, [output = tempfile()];
    [method = "GET",]
    [headers = <none>,]
    [timeout = <none>,]
    [progress = <none>,]
    [verbose = false,]
    [downloader = <default>,]
) -> output

    url :: AbstractString
    output :: Union{AbstractString, AbstractCmd, IO}
    method :: AbstractString
    headers :: Union{AbstractVector, AbstractDict}
    timeout :: Real
    progress :: (total::Integer, now::Integer) --> Any
    verbose :: Bool
    downloader :: Downloader

```

For instance, typing the following gives an error:

```julia
julia> project_file = Downloads.download(project_url, [output=tempfile()])
ERROR: syntax: misplaced assignment statement in "[output = tempfile()]" around REPL[16]:1
Stacktrace:
 [1] top-level scope
   @ REPL[16]:1

```

The docs say " Download a file from the given url, saving it to `output` or if not specified, a temporary path."

How do I change where `output` is?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [January 27, 2022, 8:29pm UTC](https://discourse.julialang.org/t/how-do-i-use-downloads-download-to-download-to-a-custom-location/75322/2 "2022-01-27T20:29:58Z")

</div>

`[]` means optional arguments, what you’re looking to do is:

```julia
project_file = Downloads.download(project_url)

```

or

```julia
project_file = Downloads.download(project_url, "path/to/somewhere")

```

in the first case, `project_file` will be a string to the downloaded file’s path (`/tmp/ something`), in the second case it will just be `"path/to/somewhere"`

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [January 27, 2022, 8:31pm UTC](https://discourse.julialang.org/t/how-do-i-use-downloads-download-to-download-to-a-custom-location/75322/3 "2022-01-27T20:31:08Z")

</div>

`output` is not a named keyword argument, it is just the second positional argument to the function (note it occurs before the semicolon `;`).

---

<div class="post-metadata">

**Author:** ![thompsonmj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thompsonmj/32/25172_2.png) [@thompsonmj](https://discourse.julialang.org/u/thompsonmj)\
**Post date:** [January 27, 2022, 8:32pm UTC](https://discourse.julialang.org/t/how-do-i-use-downloads-download-to-download-to-a-custom-location/75322/4 "2022-01-27T20:32:47Z")

</div>

Is there documentation on how to read the Julia documentation? These points aren’t self-evident just looking at a page in these docs.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [January 27, 2022, 8:35pm UTC](https://discourse.julialang.org/t/how-do-i-use-downloads-download-to-download-to-a-custom-location/75322/5 "2022-01-27T20:35:53Z")

</div>

[https://docs.julialang.org/en/v1/manual/functions/#Optional-Arguments](https://docs.julialang.org/en/v1/manual/functions/#Optional-Arguments)

> For example, the function [`Date(y, [m, d])` ](https://docs.julialang.org/en/v1/stdlib/Dates/#Dates.Date) from `Dates` module constructs a `Date` type for a given year `y` , month `m` and day `d` . However, `m` and `d` arguments are optional and their default value is `1` . This behavior can be expressed concisely as:

---

<div class="post-metadata">

**Author:** ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Post date:** [January 28, 2022, 8:38am UTC](https://discourse.julialang.org/t/how-do-i-use-downloads-download-to-download-to-a-custom-location/75322/6 "2022-01-28T08:38:25Z")

</div>

perhaps you have defined it elsewhere but `tempfile()` is not a Julia function

`(path, io) = mktemp()` is though so `tempfile = ()->mktemp()[1]` would define it

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [January 28, 2022, 9:05am UTC](https://discourse.julialang.org/t/how-do-i-use-downloads-download-to-download-to-a-custom-location/75322/7 "2022-01-28T09:05:07Z")

</div>

> [@lawless-m](#):
>
> perhaps you have defined it elsewhere but `tempfile()` is not a Julia function

You might consider making a PR to fix [https://github.com/JuliaLang/Downloads.jl/blob/43899e71eed709866f96dd624f1c369a1c8e26a3/src/Downloads.jl#L162](https://github.com/JuliaLang/Downloads.jl/blob/43899e71eed709866f96dd624f1c369a1c8e26a3/src/Downloads.jl#L162)  
Most likely `tempfile` was a typo for `tempname`. (The implementation has been changed to indirectly do this via `mktemp`, so the full story is somewhat different today.)

---

<div class="post-metadata">

**Author:** ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Post date:** [January 28, 2022, 9:10am UTC](https://discourse.julialang.org/t/how-do-i-use-downloads-download-to-download-to-a-custom-location/75322/8 "2022-01-28T09:10:18Z")

</div>

yes, it does look like a bug worth investigating

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 28, 2022, 5:10pm UTC](https://discourse.julialang.org/t/how-do-i-use-downloads-download-to-download-to-a-custom-location/75322/9 "2022-01-28T17:10:36Z")

</div>

Not really a bug, just a typo in the docs.

---

<div class="post-metadata">

**Author:** ![thompsonmj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thompsonmj/32/25172_2.png) [@thompsonmj](https://discourse.julialang.org/u/thompsonmj)\
**Post date:** [January 28, 2022, 8:50pm UTC](https://discourse.julialang.org/t/how-do-i-use-downloads-download-to-download-to-a-custom-location/75322/10 "2022-01-28T20:50:15Z")

</div>

What does the [`output = ...`] syntax mean? I understand that `[]` indicates it’s optional, but what does the assignment mean?

I’m having some trouble figuring out how to parse the `output :: Union{AbstractString, AbstractCmd, IO}` line too.

What does `AbstractCmd` mean?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [February 7, 2022, 9:18pm UTC](https://discourse.julialang.org/t/how-do-i-use-downloads-download-to-download-to-a-custom-location/75322/11 "2022-02-07T21:18:19Z")

</div>

> [@thompsonmj](#):
>
> What does the [`output = ...`] syntax mean? I understand that `[]` indicates it’s optional, but what does the assignment mean?

That’s the default value of the optional argument.

> What does `AbstractCmd` mean?

`AbstractCmd` is defined [here](https://github.com/JuliaLang/julia/blob/7b628965395f70ea5f7fad84f30a02eaf367df46/base/cmd.jl#L3), it includes commands and pipelines of commands. Basically anything that can be run with the `run` command.

> I’m having some trouble figuring out how to parse the `output :: Union{AbstractString, AbstractCmd, IO}` line too.

It means the argument can be a string, in which case it’s the path of a file to write; a command, in which case it is run as a command that consumes the download output; or an IO object, in which case it is written to.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [February 8, 2022, 5:46am UTC](https://discourse.julialang.org/t/how-do-i-use-downloads-download-to-download-to-a-custom-location/75322/12 "2022-02-08T05:46:48Z")

</div>

The Julia code base is unfortunately quite inconsistent in how optional arguments are documented which might be part of the confusion.

[https://github.com/JuliaLang/julia/issues/42319](https://github.com/JuliaLang/julia/issues/42319)  
[https://github.com/JuliaLang/julia/issues/4902](https://github.com/JuliaLang/julia/issues/4902)

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [February 8, 2022, 1:33pm UTC](https://discourse.julialang.org/t/how-do-i-use-downloads-download-to-download-to-a-custom-location/75322/13 "2022-02-08T13:33:59Z")

</div>

That’s what happens when a lot of different people write docs. If someone wants to pick a standard format and go and apply it everywhere that would accomplish consistency.

---

<div class="post-metadata">

**Author:** ![thompsonmj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thompsonmj/32/25172_2.png) [@thompsonmj](https://discourse.julialang.org/u/thompsonmj)\
**Post date:** [February 8, 2022, 3:09pm UTC](https://discourse.julialang.org/t/how-do-i-use-downloads-download-to-download-to-a-custom-location/75322/14 "2022-02-08T15:09:30Z")

</div>

@StefanKarpinski, thanks for the explanation! Very helpful.

Regarding your last post, I feel this is an appropriate place to plug Julia’s GSoD:  
[Julia’s Google Season of Docs for the main documentation](https://julialang.org/jsoc/gsod/projects/#julia_main_documentation)
