Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
How to upload file? — Gideros Forum

How to upload file?

andrecaribeandrecaribe Member
edited August 2013 in General questions
It's possible to upload a file to server like "multipart/form-data"?


  • Well you can definitely do that with LuaSocket:
    You just need to include socket.lua file to your project. You can find socket.lua file in your Gideros installation folder, inside All Plugins/LuaSocket/source
    Maybe will need to include other LuaSocket files from the same folder, didn't check.

    But I think it might also be possible to do it with UrlLoader in the same way, by simply using POST and reading in the file and setting header to "multipart/form-data"
  • I searched a lot and did several tests using this code as a basis, but the file was not going along with the message to the server. If I find the solution I'll post here.
  • ok will do some tests and get back to you ;)
  • ar2rsawseenar2rsawseen Maintainer
    edited August 2013 Accepted Answer
    Hello, this one seems to work for me:
    local filename = "crate.png"
    local file = io.open(filename, "rb")
    local contents = file:read( "*a" )
    local boundary = "somerndstring"
    local send = "--"..boundary..
    			"\r\nContent-Disposition: form-data; "..
    			"name="..filename.."; filename="..filename..
    			"\r\nContent-type: image/png"..
    local headers = {
    	["Content-Type"] = "multipart/form-data; boundary="..boundary,
    	["Content-Length"] = #send,
    local loader = UrlLoader.new("<a href="http://localhost/gideros.php"" rel="nofollow">http://localhost/gideros.php"</a>, UrlLoader.POST, headers, send)
    loader:addEventListener(Event.COMPLETE, function(e)
Sign In or Register to comment.