using lua is it possible to download from url??
Below code i have tried but not getting
1) using curl
local curl = require "luacurl"
local c = curl.new()
function GET(url)
c:setopt(curl.OPT_URL, url)
local t = {} -- this will collect resulting chunks
c:setopt(curl.OPT_WRITEFUNCTION, function (param, buf)
table.insert(t, buf) -- store a chunk of data received
return #buf
end)
c:setopt(curl.OPT_PROGRESSFUNCTION, function(param, dltotal, dlnow)
print('%', url, dltotal, dlnow) -- do your fancy reporting here
end)
c:setopt(curl.OPT_NOPROGRESS, false) -- use this to activate progress
assert(c:perform())
return table.concat(t) -- return the whole data as a string
end
local s = GET 'http://pbs.twimg.com/media/CCROQ8vUEAEgFke.jpg'
print(s)
2)
local http = require("socket.http")
local body, code = http.request("http://pbs.twimg.com/media/CCROQ8vUEAEgFke.jpg")
if not body then error(code) end
-- save the content to a file
local f = assert(io.open('/home/jiby/test.jpg', 'wb')) -- open in "binary" mode
f:write(body)
f:close()
Any other solutions??