Part 1) Download a File (from a URL)
·
253 words
·
2 minutes read
This example shows how to download a file from the web on to your local machine. By using io.Copy()
and passing the response body directly in we stream the data to the file and avoid having to load it all into the memory - it’s not a problem with small files, but it makes a difference when downloading large files.
We also have an example of downloading large files with progress reports.
If you want to use the filename from the url, you can replace the filepath
variable in DownloadFile with path.Base(resp.Request.URL.String())
and import the path
package.
|
|