I'm trying to upload an image using luaSocket.
Here is my Lua code:
Code: Select all
function uploadFile(dir)
local flen = love.filesystem.getSize(dir)
print(flen,dir)
local resp = {}
local body,code,headers,status = http.request{
url = "my_url",
method = "POST",
headers = {
["Content-Type"] = "application/x-www-form-urlencoded",
["Content-Length"] = flen
},
source = ltn12.source.file(io.open(love.filesystem.getSaveDirectory() .. "/" .. dir),"rb"),
sink = ltn12.sink.table(resp)
}
print(body,code,status)
if headers then for k,v in pairs(headers) do print(k,v) end end
end
Code: Select all
<?php
copy("php://input","test");
echo("OK");
But the script works fine if I try to upload a text file.
Any help is appreciated. Thanks.