Skip to content

Instantly share code, notes, and snippets.

@legumbre
Created November 8, 2012 19:21
Show Gist options
  • Save legumbre/4040928 to your computer and use it in GitHub Desktop.
Save legumbre/4040928 to your computer and use it in GitHub Desktop.
http = require("socket.http")
ltn12 = require("ltn12")
function fsize (file)
local current = file:seek() -- get current position
local size = file:seek("end") -- get file size
file:seek("set", current) -- restore position
return size
end
pathToLocalFile="/tmp/server.py"
file = io.open(pathToLocalFile, "r")
sizeOfFile= fsize(file)
print(sizeOfFile)
file:close()
function upload ()
local response_body={}
socket.http.request{
url = "http://localhost:8000/upload",
method = "POST",
headers = {
["Content-Type"] = "multipart/form-data",
["Content-Length"] = sizeOfFile
},
source = ltn12.source.file(io.open(pathToLocalFile)),
sink = ltn12.sink.table(response_body)
}
print(response_body[1])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment