[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:42:47 +0100
On 4 March 2013 10:31, albert <albert_200200@126.com> wrote:
> If the data file to upload is like 2k, it worked fine, but if the data file
> is like 2M or bigger, then commit error:
> String returned from readfunction is too long (4419973)
>
> How could I correct my uploading code? And thanks for the reply.
Open the file outside of readfunction, and in readfunction, just read
a few (kilo)bytes of data and return it. The function will be called
repeatedly by curl.
It would look like this (untested code):
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")