Page 1 of 1

Upload image with LuaSocket

Posted: Wed Aug 19, 2015 4:27 pm
by bio1712
Hello everyone.

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
My php code is:

Code: Select all

<?php
  copy("php://input","test");
  echo("OK");
When I try to upload the image I don't get any error but body and status are nil, but code is "timeout".
But the script works fine if I try to upload a text file.

Any help is appreciated. Thanks.

Re: Upload image with LuaSocket

Posted: Wed Aug 19, 2015 4:53 pm
by ArchAngel075
whats the size of your image? in the past i used luaSocket to make players able to upload a image to wrap around a babo (Baboviolent remake)
I found it wouldnt allow images above a size to be sent - the only workaround is to implement fragment packets (breakup your image into many packets that are reconstructed on receiver side)

Lua-Enet has a built in fragmenting implementation i believe.

Re: Upload image with LuaSocket

Posted: Wed Aug 19, 2015 5:02 pm
by bio1712
Thanks for the reply.

I have tried uploading a test image, it is 32x32 and it is only 1 kb.

Re: Upload image with LuaSocket

Posted: Wed Aug 19, 2015 5:14 pm
by ArchAngel075
unsure then what could be causing it to not work as expected. Only other issue is formatting or file type i think...

Re: Upload image with LuaSocket

Posted: Wed Aug 19, 2015 5:21 pm
by bio1712
Ok, thanks for your time.