lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 2013/3/4 16:42, Kevin Martin wrote:
On 4 Mar 2013, at 02:41, albert wrote:

However this example can't fulfill my requirement, I want to upload a local exist file while not a trash file.
Did it work properly with the example function?

I change the readfunction to my code below:

c:perform({readfunction=function(n)
  local datafilename = "mydatafile"
  local fhandle = io.open(datafilename, "r")
  local datafromfile = nil
  if nil ~= fhandle then
      datafromfile = fhandle:read("*all")
      fhandle:close()
  end
  return datafromfile
          end})
But my code didn't work.
Can you be a bit more specific? What actually happens? Do you get an error/segfault/only part of the file?

The two things that jump out at me are:

o Are you sure fhandle is valid?
o Is the file size larger than n?

Thanks,
Kevin





require("cURL")
c=cURL.easy_init()
c:setopt_url("ftp://ftptest:secret0815@targethost/file.dat";)
c:setopt_upload(1)
count=0
c:perform({readfunction=function(n)
               count = count + 1
               if (count < 10)  then
                  return "Line " .. count .. "\n"
               end
               return nil
            end})
print("Fileupload done")
The example code works correctly.

Now I change the example code to:
require("cURL")

c=cURL.easy_init()
c:setopt_url("ftp://ftptest:secret0815@targethost/file.dat";)
c:setopt_upload(1)
local upmgr = 0
c:perform({readfunction=function(n)
    local datafilename = "mydatafile"
    local fhandle = io.open(datafilename, "r")
    local datafromfile = nil
    if nil ~= fhandle then
        datafromfile = fhandle:read("*all")
        fhandle:close()
    end
    if upmgr == 0 then
        upmgr = upmgr + 1
        return datafromfile
    else
        return nil
    end
            end})
print("Fileupload done")

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.