Downloading from an HTTP server is done by a Task asynchronously (other Tasks will be executed concurrently without blocking execution flow)
Http:download(uri)
Send an asynchronous GET request to the connected HTTP server to download the specified resource from the server.
Parameters
uri
A string
representing the target resource on the server to be downloaded.
Return value
This method return a Task instance. Once the Task has finished, it will return two values :
- The first value is the Http instance used for the PUT request.
- The second value is
nil
in case of error or atable
that contains the server response, with the following fields "file"
: a File object instance representing the downloaded file. The file is dowloaded in the current directory."elapsed"
: anumber
representing the elapsed time to get the response"status"
: anumber
containing the HTTP response status"reason"
: astring
containing HTTP response status text"ok"
: aboolean
value indicating if the GET request succeeded"headers"
: atable
containing a pair ofstrings
(header field names of the HTTP response as key and content as values)"cookies"
: atable
containing a pair ofstrings
(cookies names of the HTTP response as key and content as values)
Example
local net = require "net"
-- Download a server resource and waits until it's done
local client, response = await(net.Http("http://download.thinkbroadband.com"):download("/10MB.zip"))
print("Downloaded "..response.file.name..", "..response.file.size.." bytes")