Upload image with LuaSocket

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
bio1712
Citizen
Posts: 72
Joined: Wed Aug 19, 2015 4:13 pm
Location: Italy

Upload image with LuaSocket

Post 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.
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: Upload image with LuaSocket

Post 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.
bio1712
Citizen
Posts: 72
Joined: Wed Aug 19, 2015 4:13 pm
Location: Italy

Re: Upload image with LuaSocket

Post by bio1712 »

Thanks for the reply.

I have tried uploading a test image, it is 32x32 and it is only 1 kb.
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: Upload image with LuaSocket

Post by ArchAngel075 »

unsure then what could be causing it to not work as expected. Only other issue is formatting or file type i think...
bio1712
Citizen
Posts: 72
Joined: Wed Aug 19, 2015 4:13 pm
Location: Italy

Re: Upload image with LuaSocket

Post by bio1712 »

Ok, thanks for your time.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests