[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua-cURL How to upload a file?
- From: Michal Kottman <michal.kottman@...>
- Date: Mon, 4 Mar 2013 10:59:21 +0100
On 4 March 2013 10:42, Michal Kottman <michal.kottman@gmail.com> wrote:
> local datafilename = "mydatafile"
> local fhandle = assert(io.open(datafilename, "rb"))
>
> c:perform({readfunction=function(n)
> -- read up to 4096 bytes from the file, and pass it back to libcurl
> -- if less than 4096 bytes are read (near the end of file),
> libcurl will still process it
> -- at the end of file, it will return nil, which also signals
> libcurl to stop
> return fhandle:read(4096)
> end})
> print("Fileupload done")
After better reading the docs, one warning - the `n` parameter you see
in readfunction is the maximal number of bytes libcurl expects. For my
setup it is 16KiB, so my example would work, but just to be safe (and
efficient) you should do this:
c:perform( { readfunction = function(n)
return fhandle:read(n)
end } )